Skip to content

Fix Visual mode flip on project search #44284

Merged
dinocosta merged 5 commits intozed-industries:mainfrom
MostlyKIGuess:deploy-search-fix
Jan 22, 2026
Merged

Fix Visual mode flip on project search #44284
dinocosta merged 5 commits intozed-industries:mainfrom
MostlyKIGuess:deploy-search-fix

Conversation

@MostlyKIGuess
Copy link
Contributor

@MostlyKIGuess MostlyKIGuess commented Dec 6, 2025

  • Prevent incorrect visual-mode activation when opening project search results by ensuring selections made before the editor gains focus

Some Diagnosis:

  • The results editor got created before collapse_matches was initialized -> giving range_for_match a full selection instead of a collapsed cursor.
  • When the editor finally focused and Vim synced settings, it saw that non-empty selection -> flip into Visual mode.
  • From what I understand, it happened only on the first run because: the editor is not focused yet when created, so sync_vim_settings is not called. This means collapse_matches is still false (the default). ( so when called from project_search.rs L1515 collapse matches is false and later on it focuses on the editor and due to that it changes to visual. )

Closes #43878

Release Notes:

  • Fixed vim mode incorrectly switching to Visual mode on first project search

- Prevent incorrect visual-mode activation when opening project search
  results by ensuring selections made before the editor gains focus
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Dec 6, 2025
@MostlyKIGuess MostlyKIGuess changed the title fix: set collapse_matches before registering Vim addon fix: Set collapse_matches before registering Vim addon Dec 6, 2025
@MostlyKIGuess
Copy link
Contributor Author

Intended Behavior demo

@maxdeviant maxdeviant changed the title fix: Set collapse_matches before registering Vim addon Set collapse_matches before registering Vim addon Dec 6, 2025
@ovidius72
Copy link

Intended Behavior demo

Looks great. Did you do some tests when you go back to the file where the search started from? I found it also to be in visual mode.

@MostlyKIGuess
Copy link
Contributor Author

Intended Behavior demo

Looks great. Did you do some tests when you go back to the file where the search started from? I found it also to be in visual mode.

Yeah, it is normal for me, can you share a video?

I tried going back via ctrl tab and g space as well.. seems to be fine

@MostlyKIGuess
Copy link
Contributor Author

I meant in my version, it stays in normal fixing the bug.

@ovidius72
Copy link

I meant in my version, it stays in normal fixing the bug.

Thanks. Great job. I'm going to check it as soon as it will be released and, eventually, i'll send you a video.

@MostlyKIGuess MostlyKIGuess changed the title Set collapse_matches before registering Vim addon Fix Visual mode flip on project search Dec 8, 2025
@zelenenka zelenenka assigned dinocosta and unassigned yara-blue Jan 20, 2026
Copy link
Member

@dinocosta dinocosta left a comment

Choose a reason for hiding this comment

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

@MostlyKIGuess Thank you so much for tackling this! Appreciate the detailed diagnosis in the PR's description, helps frame the suggested changes ✌️

I noticed that, since we're updating Vim::activate to set the collapse_matches field, we might as well try to actually sync all settings, like Vim.sync_settings is doing, so I'm wrapping up a commit with these changes.

Will merge soon! 🙂

Previously, vim settings like `collapse_matches` were only synced to an
editor when it received focus via `EditorEvent::FocusedIn`. This could
leading to timing issues with, for example, project search, as when the
results editor was created, `collapse_matches` remained false, so
selecting the first match would create a non-empty selection, causing
vim to switch to Visual mode.

This commit refactors `sync_vim_settings` to extract settings into a
`VimEditorSettingsState` struct and apply them via
`sync_vim_settings_to_editor`. This allows `Vim::activate` to sync
settings immediately without re-entrantly borrowing the editor.

Also adds regression tests for both vim and helix modes to ensure
project search opens in the correct mode (Normal/HelixNormal).
@dinocosta dinocosta merged commit d42fe0b into zed-industries:main Jan 22, 2026
27 checks passed
@github-project-automation github-project-automation bot moved this from Community PRs to Done in Quality Week – December 2025 Jan 22, 2026
zcg pushed a commit to zcg/zedpro that referenced this pull request Jan 29, 2026
Previously, when project search results first appeared, vim would
incorrectly switch to Visual mode. This happened because vim settings
(including `collapse_matches`) weren't synced to an editor until it
received focus. Since the results editor wasn't focused when the first
match was selected, the selection wasn't collapsed, causing vim to
interpret it as a visual selection.

Now vim settings are synced immediately when vim activates on an editor,
ensuring `collapse_matches` is set before any selections are made.

Closes zed-industries#43878

Release Notes:

- Fixed vim mode incorrectly switching to Visual mode on first project
search

---------

Co-authored-by: dino <dinojoaocosta@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

Development

Successfully merging this pull request may close these issues.

Vim mode: project search results are in visual mode on first run

4 participants