Fix Visual mode flip on project search #44284
Conversation
- Prevent incorrect visual-mode activation when opening project search results by ensuring selections made before the editor gains focus
|
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 |
|
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. |
dinocosta
left a comment
There was a problem hiding this comment.
@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).
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>
Some Diagnosis:
sync_vim_settingsis not called. This meanscollapse_matchesis stillfalse(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: