commit ec27c00574d6b4a1c79863d7975f67a79dca97c9
parent 6eb321f4f5e9607c60000e60d6e528efaff69a19
Author: Michael Camilleri <[email protected]>
Date: Thu, 22 Oct 2026 15:04:39 +0900
Clear search field on manual selection
Diffstat
| M | Reportage/Views/Survey/SurveyModel.swift | | | 6 | +++++- |
| M | Tests/Unit/SurveyModelTests.swift | | | 11 | +++++++++++ |
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/Reportage/Views/Survey/SurveyModel.swift b/Reportage/Views/Survey/SurveyModel.swift
@@ -376,14 +376,18 @@ final class TokenPicker {
func isSelected(_ id: String) -> Bool { selection.contains(id) }
+ /// Selects or deselects `id`. Selecting clears the query.
func toggle(_ id: String) {
if let position = selection.firstIndex(of: id) {
selection.remove(at: position)
- } else if allowsMultiple {
+ return
+ }
+ if allowsMultiple {
selection.append(id)
} else {
selection = [id]
}
+ query = ""
}
/// Selects the entry `query` names, adding it as a new token if there's
diff --git a/Tests/Unit/SurveyModelTests.swift b/Tests/Unit/SurveyModelTests.swift
@@ -358,6 +358,17 @@ struct TokenPickerTests {
#expect(picker.visibleEntries.map(\.id) == ["1", "2", "3"])
}
+ @Test("Selecting an entry clears the query")
+ func selectClearsQuery() {
+ let picker = makePicker()
+ picker.query = "read"
+ picker.toggle("1")
+ #expect(picker.query.isEmpty)
+ picker.query = "cook"
+ picker.toggle("1")
+ #expect(picker.query == "cook")
+ }
+
@Test("Single selection replaces the selected entry")
func singleSelection() {
let picker = makePicker(allowsMultiple: false)