Skip to content

search: Fix focus replacement field when opening replace (Ctrl+H)#51061

Merged
Veykril merged 5 commits intozed-industries:mainfrom
CCXLV:replace-focus-fix
Mar 23, 2026
Merged

search: Fix focus replacement field when opening replace (Ctrl+H)#51061
Veykril merged 5 commits intozed-industries:mainfrom
CCXLV:replace-focus-fix

Conversation

@CCXLV
Copy link
Copy Markdown
Contributor

@CCXLV CCXLV commented Mar 8, 2026

Previously, focus stayed on the search bar because a pre-focus check handle.is_focused(window) was always false at deploy time.

Before you mark this PR as ready for review, make sure that you have:

  • Added a solid test coverage and/or screenshots from doing manual testing
  • Done a self-review taking into account security and performance aspects
  • Aligned any UI changes with the UI checklist

Release Notes:

  • Fixed: When opening find-and-replace with Ctrl+H, the replacement input is now focused instead of the search bar.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 8, 2026
@dinocosta dinocosta added the area:search buffer search, project search, etc label Mar 9, 2026
@Veykril
Copy link
Copy Markdown
Member

Veykril commented Mar 16, 2026

I don't think this is the behavior we want here. We should be focusing the search editor first, as that needs to be populated either way. What we should instead consider is having the opening replace action toggling focus between the search and replace editors if either of them is currently focused

@Veykril Veykril self-assigned this Mar 16, 2026
@CCXLV
Copy link
Copy Markdown
Contributor Author

CCXLV commented Mar 16, 2026

I don't think this is the behavior we want here. We should be focusing the search editor first, as that needs to be populated either way. What we should instead consider is having the opening replace action toggling focus between the search and replace editors if either of them is currently focused

I understand your suggestion, but my original thought was to optimize for the specific case where a user has already made a selection and triggers a replace, in that case user is almost always looking to immediately type into the replace field. Currently the extra tab navigation to get to the replace field feels like a bit extra step which in my opinion is poor UX.

For context thats how VSCode handles this specific case.

@Veykril
Copy link
Copy Markdown
Member

Veykril commented Mar 16, 2026

Ah right, with a selection that would make sense, then we should only make it do that in that case though. If I understand your change correctly here this will always focus the replace editor

@CCXLV
Copy link
Copy Markdown
Contributor Author

CCXLV commented Mar 16, 2026

Yes currently it always focuses the replace field. I'll have a look into it.

@CCXLV
Copy link
Copy Markdown
Contributor Author

CCXLV commented Mar 16, 2026

I split this into two commits: first tries using query_suggestion().is_some() to detect selection for replace-focus. That turned out to conflate real selections with cursor-word seeding, so the follow-up commit adds has_non_empty_selection for SearchableItem and switches the focus logic to use that instead. So it now reflects the actual selection

@CCXLV
Copy link
Copy Markdown
Contributor Author

CCXLV commented Mar 19, 2026

I think that's it.

Copy link
Copy Markdown
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Veykril
Copy link
Copy Markdown
Member

Veykril commented Mar 23, 2026

can you rebase on top of main once more? I think the CI step is bugged on the branch base you are on

@CCXLV CCXLV force-pushed the replace-focus-fix branch from d1b4ea5 to ffeeea2 Compare March 23, 2026 09:02
@Veykril Veykril enabled auto-merge (squash) March 23, 2026 09:03
@Veykril Veykril merged commit 4b1a2f3 into zed-industries:main Mar 23, 2026
31 checks passed
@CCXLV CCXLV deleted the replace-focus-fix branch March 23, 2026 09:48
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 23, 2026
…d-industries#51061)

Previously, focus stayed on the search bar because a pre-focus check
`handle.is_focused(window)` was always false at deploy time.

Before you mark this PR as ready for review, make sure that you have:
- [x] Added a solid test coverage and/or screenshots from doing manual
testing
- [x] Done a self-review taking into account security and performance
aspects
- [x] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- Fixed: When opening find-and-replace with `Ctrl+H`, the replacement
input is now focused instead of the search bar.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:search buffer search, project search, etc cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants