editor: Refocus the search bar when search is invoked again - #2932
Merged
Conversation
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
force-pushed
the
fix-editor-search-bar
branch
from
September 4, 2026 11:13
7b4e31a to
1a14b63
Compare
huacnlee
enabled auto-merge (squash)
September 4, 2026 11:13
Member
|
Thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes:
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_searchnow advancesInputBaseState::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 onSearchSession, whose fields are allpub— adding one there would break every downstream struct literal.SearchSessionis 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_queryManual,
cargo r --example editor:Issue 1
Issue 2
Checklist
cargo runfor story tests related to the changes.