fix: no-op unknown removal, earlier-duplicate editor check, list focus for delete/undo
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -21,6 +21,7 @@ struct DictionaryView: View {
|
||||
@State private var selection: UUID?
|
||||
@State private var editing: EditorTarget?
|
||||
@FocusState private var searchFocused: Bool
|
||||
@FocusState private var listFocused: Bool
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: Layout.panelGap) {
|
||||
@@ -77,14 +78,25 @@ struct DictionaryView: View {
|
||||
ForEach(list.visibleRows) { row in
|
||||
DictionaryRow(row: row, isSelected: selection == row.id)
|
||||
.onTapGesture(count: 2) { editing = .existing(row.id) }
|
||||
.onTapGesture { selection = row.id }
|
||||
.onTapGesture {
|
||||
selection = row.id
|
||||
listFocused = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.focusable()
|
||||
.focused($listFocused)
|
||||
.focusEffectDisabled()
|
||||
.onDeleteCommand {
|
||||
if let id = selection { list.remove(id: id) }
|
||||
if let id = selection {
|
||||
list.remove(id: id)
|
||||
selection = nil
|
||||
}
|
||||
}
|
||||
.onChange(of: list.rows) { _, rows in
|
||||
if let s = selection, !rows.contains(where: { $0.id == s }) { selection = nil }
|
||||
}
|
||||
.onKeyPress(KeyEquivalent("z"), phases: .down) { press in
|
||||
guard press.modifiers == .command, list.canUndo else { return .ignored }
|
||||
|
||||
@@ -10,6 +10,7 @@ struct HistoryView: View {
|
||||
@EnvironmentObject private var model: AppModel
|
||||
@ObservedObject var list: HistoryViewModel
|
||||
@FocusState private var searchFocused: Bool
|
||||
@FocusState private var listFocused: Bool
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: Layout.panelGap) {
|
||||
@@ -47,6 +48,9 @@ struct HistoryView: View {
|
||||
}
|
||||
}
|
||||
.focusable()
|
||||
.focused($listFocused)
|
||||
.focusEffectDisabled()
|
||||
.onChange(of: list.selection) { _, _ in listFocused = true }
|
||||
.onDeleteCommand {
|
||||
if let id = list.selection { list.delete(id: id) }
|
||||
}
|
||||
|
||||
@@ -134,7 +134,14 @@ public final class DictionaryViewModel: ObservableObject {
|
||||
|
||||
/// Live feedback for the editor; `id` is the entry being edited (nil for a new one).
|
||||
public func warnings(for kind: DictionaryEntry.Kind, editing id: UUID?) -> [EntryWarning] {
|
||||
EntryWarnings.check(kind, among: store.entries.filter { $0.id != id }, knowledge: knowledge)
|
||||
let entries = store.entries
|
||||
let others: [DictionaryEntry]
|
||||
if let id, let index = entries.firstIndex(where: { $0.id == id }) {
|
||||
others = Array(entries[..<index])
|
||||
} else {
|
||||
others = entries
|
||||
}
|
||||
return EntryWarnings.check(kind, among: others, knowledge: knowledge)
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
@@ -149,6 +156,7 @@ public final class DictionaryViewModel: ObservableObject {
|
||||
}
|
||||
|
||||
public func remove(id: UUID) {
|
||||
guard store.entries.contains(where: { $0.id == id }) else { return }
|
||||
mutate { $0.remove(id: id) }
|
||||
}
|
||||
|
||||
|
||||
@@ -170,4 +170,21 @@ struct DictionaryViewModelTests {
|
||||
let asNew = model.warnings(for: .correction(heard: "cloud code", wrote: "Other"), editing: nil)
|
||||
#expect(asNew.contains { $0.level == .error })
|
||||
}
|
||||
|
||||
@Test func removingAnUnknownIdChangesNothing() throws {
|
||||
let (model, store) = try makeModel("Supabase\n")
|
||||
let before = store.entries
|
||||
model.remove(id: UUID())
|
||||
#expect(store.entries == before)
|
||||
#expect(model.canUndo == false)
|
||||
}
|
||||
|
||||
@Test func editingTheEarlierOfTwoDuplicatesShowsNoDuplicateError() throws {
|
||||
let (model, store) = try makeModel("cloud code => A\nCloud-Code => B\n")
|
||||
let first = store.entries[0]
|
||||
let second = store.entries[1]
|
||||
#expect(!model.warnings(for: first.kind, editing: first.id).contains { $0.level == .error })
|
||||
#expect(model.warnings(for: second.kind, editing: second.id).contains { $0.level == .error })
|
||||
#expect(model.warnings(for: first.kind, editing: nil).contains { $0.level == .error })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user