Find bar X clears the query instead of closing the bar

The X was redundant with the top-bar search icon (both closed the bar).
Now the X empties the query and results but leaves the bar open; closing
is the search icon's toggle.

- editor: new findClear (empties query/matches, bumps Gen so an in-flight
  scan of the old query is dropped, disarms the settle) and FindClear
  handler; the X icon now runs FindClear.
- main: mirrors the logic-side clear into the main-owned widget input
  (frame.FindQuery=="" while the widget still has text -> SetText("")).
- tests: unit findClear (stays open, supersedes in-flight scan); e2e X
  clears but keeps the bar open and focus, close now via ToggleFind.
- doc: spec updated (clear button vs icon toggle).
This commit is contained in:
gmp
2026-08-20 13:00:21 -04:00
parent 1cbb367b1f
commit d726ea7244
6 changed files with 75 additions and 11 deletions
+16 -3
View File
@@ -177,13 +177,26 @@ func TestRealFile_FindBarAndNavigation(t *testing.T) {
t.Fatalf("cur %d, want last (wrapped)", cur)
}
// The X button clears the query but LEAVES the bar open (closing is the
// top-bar icon's toggle).
h.SendInput([]ui.InputEvent{{Handler: editor.FindClear, Data: ui.Point{}}})
if !frameHasFindBar(h) {
t.Fatal("find bar closed by the clear button; it should stay open")
}
clear, _ := h.Inspect(func(st *editor.State) any {
return [3]any{st.Editor.Find.Query, len(st.Editor.Find.Matches), st.FocusedElementID}
})
if clear.([3]any) != [3]any{"", 0, "find_bar"} {
t.Fatalf("after clear: query/matches/focus = %v, want \"\"/0/find_bar", clear)
}
// A query with no hits reports zero matches.
h.Logic().FindQueryChan() <- "no-such-text"
waitForFindMatches(t, h, 0)
// Close the find bar: it leaves the frame and focus returns to the
// editor.
h.SendInput([]ui.InputEvent{{Handler: editor.FindClose, Data: ui.Point{}}})
// Close the find bar via the top-bar icon toggle: it leaves the frame
// and focus returns to the editor.
h.SendInput([]ui.InputEvent{{Handler: editor.ToggleFind, Data: ui.Point{}}})
if _, err := h.WaitForFrameCount(h.FrameCount()+1, 5*time.Second); err != nil {
t.Fatalf("wait for close frame: %v", err)
}