Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions Cotabby/UI/CustomRulesEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import SwiftUI
/// File overview:
/// Editor for the user's custom autocomplete rules. Rules are short imperative style directives
/// (e.g. "Use British spelling") shown as removable chips, added freeform or by tapping a suggested
/// chip. "Clear" removes every rule (rules are opt-in, so the baseline is empty).
/// chip. A bottom "Reset" button removes every rule (rules are opt-in, so the baseline is empty).
///
/// The chip and flow-layout primitives live in `TagChip.swift`, shared with `LanguageTagsEditor`.
struct CustomRulesEditor: View {
@ObservedObject var suggestionSettings: SuggestionSettingsModel

/// When false, the editor drops its own "Rules" title so an enclosing `Section("Rules")` can
/// supply the heading without duplicating it. The Clear control stays in place either way.
/// supply the heading without duplicating it. The Reset control stays in place either way.
/// Defaults to true so standalone uses (e.g. onboarding) keep their inline title.
var showsTitleHeader: Bool = true

Expand All @@ -32,22 +32,9 @@ struct CustomRulesEditor: View {

var body: some View {
VStack(alignment: .leading, spacing: 14) {
if showsTitleHeader || canClear {
HStack {
if showsTitleHeader {
Text("Rules")
.font(.system(size: 13, weight: .medium))
}
Spacer()
if canClear {
Button("Clear") {
suggestionSettings.clearRules()
}
.buttonStyle(.plain)
.font(.system(size: 12))
.foregroundStyle(.secondary)
}
}
if showsTitleHeader {
Text("Rules")
.font(.system(size: 13, weight: .medium))
}

if !rules.isEmpty {
Expand Down Expand Up @@ -87,6 +74,18 @@ struct CustomRulesEditor: View {
}
}
}

if canClear {
HStack {
Spacer()
Button {
suggestionSettings.clearRules()
} label: {
Label("Reset", systemImage: "arrow.counterclockwise")
}
.controlSize(.small)
}
}
}
}

Expand Down
37 changes: 18 additions & 19 deletions Cotabby/UI/LanguageTagsEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import SwiftUI
/// File overview:
/// Editor for the languages the user writes in. Mirrors `CustomRulesEditor`: declared languages are
/// removable chips, added by tapping a suggestion (shown with its native name) or typing a custom
/// one. "Clear" removes them all. The baseline is empty, which means "just follow the surrounding
/// text." The chip and flow-layout primitives are shared via `TagChip.swift`.
/// one. A bottom "Reset" button restores the default language set. The chip and flow-layout
/// primitives are shared via `TagChip.swift`.
struct LanguageTagsEditor: View {
@ObservedObject var suggestionSettings: SuggestionSettingsModel

/// When false, the editor drops its own "Languages" title so an enclosing `Section("Languages")`
/// can supply the heading without duplicating it. The Clear control stays in place either way.
/// can supply the heading without duplicating it. The Reset control stays in place either way.
/// Defaults to true so standalone uses (e.g. onboarding) keep their inline title.
var showsTitleHeader: Bool = true

Expand All @@ -31,22 +31,9 @@ struct LanguageTagsEditor: View {

var body: some View {
VStack(alignment: .leading, spacing: 14) {
if showsTitleHeader || canClear {
HStack {
if showsTitleHeader {
Text("Languages")
.font(.system(size: 13, weight: .medium))
}
Spacer()
if canClear {
Button("Clear") {
suggestionSettings.clearLanguages()
}
.buttonStyle(.plain)
.font(.system(size: 12))
.foregroundStyle(.secondary)
}
}
if showsTitleHeader {
Text("Languages")
.font(.system(size: 13, weight: .medium))
}

if !languages.isEmpty {
Expand Down Expand Up @@ -93,6 +80,18 @@ struct LanguageTagsEditor: View {
+ "set of languages, and local models vary, so some languages may not work.")
.font(.caption2)
.foregroundStyle(.tertiary)

if canClear {
HStack {
Spacer()
Button {
suggestionSettings.clearLanguages()
} label: {
Label("Reset", systemImage: "arrow.counterclockwise")
}
.controlSize(.small)
}
}
}
}

Expand Down