Stop the find input clearing itself while typing

The main-loop mirror of the X-button clear was level-triggered:
'FindQuery=="" && widget has text'. But the widget updates on every
keystroke while the logic only stores the query a round-trip later, so any
frame drawn in that window still carried FindQuery=="" and wiped the input
- the periodic self-clearing.

Make it edge-triggered: FindState.ClearSeq bumps once per clear; the frame
carries it as FindClearSeq; main wipes the widget input once per NEW value
(lastFindClearSeq handshake). findClear bumps it; findReset preserves it
(main tracks it monotonically, so a reset to 0 would swallow a later clear).

Tests: unit asserts the bump, monotonicity, and close/reopen preservation.
This commit is contained in:
gmp
2026-08-20 13:22:50 -04:00
parent d726ea7244
commit c789de4b44
4 changed files with 44 additions and 6 deletions
+12 -5
View File
@@ -132,6 +132,10 @@ func run(w *app.Window) error {
// main-owned input, so main hands key focus to it exactly once per open
// (see the focus handoff below).
var findBarFocused bool
// lastFindClearSeq is the FindClearSeq value whose wipe has already been
// applied to the main-owned find input (edge-triggered, see
// Frame.FindClearSeq).
var lastFindClearSeq int
for {
switch e := w.Event().(type) {
@@ -218,12 +222,15 @@ func run(w *app.Window) error {
// The logic goroutine handles filtering and triggers a new frame.
newQuery := searchEditor.Text()
sendQuery := newQuery != frame.Query
// The find bar's X button (editor.FindClear) empties the LOGIC-side
// query; the main-owned widget still shows the old text, so mirror
// the clear into it before the change comparison below (which then
// sees "" == "" and forwards nothing).
if frame.FindQuery == "" && findEditor.Text() != "" {
// Mirror each NEW find-clear (the bar's X button) into the main-
// owned widget input exactly once. Edge-triggered on ClearSeq, NOT
// "FindQuery==\"\" && widget has text": that level check also fired on
// stale frames between the user's typing and the logic storing it,
// wiping the input while typing.
if frame.FindClearSeq > lastFindClearSeq {
lastFindClearSeq = frame.FindClearSeq
findEditor.SetText("")
w.Invalidate()
}
newFind := findEditor.Text()
sendFind := newFind != frame.FindQuery