Skip to content

editor: Refocus the search bar when search is invoked again - #2932

Merged
huacnlee merged 6 commits into
longbridge:mainfrom
hlcfan:fix-editor-search-bar
Sep 4, 2026
Merged

editor: Refocus the search bar when search is invoked again#2932
huacnlee merged 6 commits into
longbridge:mainfrom
hlcfan:fix-editor-search-bar

Conversation

@hlcfan

@hlcfan hlcfan commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes:

  • In an editor, pressing Cmd+F shows the search bar, but the caret is not showing.
  • In an editor with the search bar shown and its input not focused, pressing Cmd+F does not re-focus the search input.

The overlay decides what to rebuild by comparing search-session state, and re-invoking search leaves that state identical, so the second request is dropped. open_search now advances InputBaseState::search_activation_revision, and the sync folds that counter into its comparison, so the input is focused every time. All other render and sync passes remain unchanged and are still skipped.

The counter lives on InputBaseState, whose fields are all private, rather than on SearchSession, whose fields are all pub — adding one there would break every downstream struct literal. SearchSession is untouched, so there are no API changes.

Screenshot

Before

Before.fix.mov

After

After.fix.mov

Break Changes

NA

How to Test

Automated — this test fails without the fix, with the caret left where the user put it instead of the query being selected again:

cargo test -p gpui-component --lib input::overlay::tests::reopening_search_reselects_the_query

Manual, cargo r --example editor:

Issue 1

  • Press Cmd+F. The search bar appears with a blinking caret.

Issue 2

  • Press Cmd+F to show the search bar and type a query.
  • Click back into the editor, leaving nothing selected, so the search bar loses focus.
  • Press Cmd+F again. Focus returns to the search bar and the query is selected.

Leave nothing selected in step 2. Selecting text seeds a new query, which the sync notices on its own — the bug only shows when re-invoking search changes nothing else.

Checklist

  • I have read the CONTRIBUTING document and followed the guidelines.
  • Reviewed the changes in this PR and confirmed AI generated code (If any) is accurate.
  • Passed cargo run for story tests related to the changes.
  • Tested macOS, Windows and Linux platforms performance (if the change is platform-specific)

@hlcfan hlcfan changed the title editor: Fix editor search bar editor: Fix editor search bar focus issues Sep 3, 2026
hlcfan and others added 4 commits September 3, 2026 21:40
The refocus fix needs a counter that moves when search is invoked again on
an already-open session, so the overlay sync can tell "still open" from
"asked for again". It was living on `SearchSession`, whose fields are all
`pub`: adding one there breaks every downstream struct literal, and — as
`E0451` — every `..Default::default()` too.

`InputBaseState` has no `pub` fields at all, so it can hold the counter
without any downstream breakage. Bumping it in `open_search` is also more
honest than bumping it in `SearchSession::open`, which cannot see the
`searchable` early return.

Also here:

- Fold the search signature's five-tuple into a named `SearchSignature`,
  matching `OverlaySignature` in the same file. The query-echo guard is
  five `&&` clauses deep and was reading positional tuple bindings.
- Say in `open_search`'s doc that it is not idempotent, so nobody calls it
  from a render pass and re-selects the field on every frame.
- Cover the regression: `reopening_search_reselects_the_query` fails
  without the revision, with the caret left where the user put it instead
  of the query being selected again.
- Give `hide_with_focus` the same shape as `show_with_focus` by focusing
  the editor through `InputBaseState::focus` inside the update it already
  runs.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AEg8SEHNEgRDcZ9mDj1p6r
@huacnlee huacnlee changed the title editor: Fix editor search bar focus issues editor: Refocus the search bar when search is invoked again Sep 4, 2026
@huacnlee
huacnlee force-pushed the fix-editor-search-bar branch from 7b4e31a to 1a14b63 Compare September 4, 2026 11:13
@huacnlee
huacnlee enabled auto-merge (squash) September 4, 2026 11:13
@huacnlee

huacnlee commented Sep 4, 2026

Copy link
Copy Markdown
Member

Thanks.

@huacnlee
huacnlee merged commit 68e6840 into longbridge:main Sep 4, 2026
9 checks passed
@hlcfan
hlcfan deleted the fix-editor-search-bar branch September 4, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants