Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vim: Handle visual selection when jumping to mark #25360

Merged

Conversation

dinocosta
Copy link
Contributor

Fix how vim mode handles jumping to mark, when one of vim's visual modes is active, in order to behave just like neovim. Here's a quick video showing the updated behavior ↓

vim_visual_selection_marks.mov

Closes #18131

Release Notes:

  • Fixed vim's visual selections when jumping to marks

Fix the way selections are handled when jumping to marks in Vim mode so
as to not reset these when vim is in visual mode.
Fix regression in mark's behaviour, where a mark with multiple anchors
was not activating all anchors again when jumping to that mark in
normal mode, as `Motion::Jump` was being used even if not in visual
mode.

This commit fixes the issue by only using jump motion if in visual
mode, making sure that the behaviour stays the same as before.
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 21, 2025
@maxdeviant maxdeviant changed the title fix(vim): handle visual selection when jumping to mark vim: Handle visual selection when jumping to mark Feb 21, 2025
@dinocosta
Copy link
Contributor Author

@ConradIrwin Opened this Pull Request after this message, thank you so much for the help!

By the way, I've noticed that, for a mark with multiple anchors, with this small change:

diff --git a/crates/vim/src/normal/mark.rs b/crates/vim/src/normal/mark.rs
index 7040d55afd..381fd87ecb 100644
--- a/crates/vim/src/normal/mark.rs
+++ b/crates/vim/src/normal/mark.rs
@@ -144,11 +144,9 @@ impl Vim {
                     }
                 }
 
-                if !should_jump {
-                    editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
-                        s.select_anchor_ranges(ranges)
-                    });
-                }
+                editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
+                    s.select_anchor_ranges(ranges)
+                });
             });
 
             if should_jump && anchor.is_some() {

We can get the visual selection to be applied between the first and last anchor. Here's a quick video, let me know if you think that makes more sense than just jumping to the last anchor and I'll update these changes:

visual_mode_jump_multiple_anchors.mov

Thanks! 🙇

@ConradIrwin ConradIrwin merged commit 5d751cd into zed-industries:main Feb 22, 2025
12 checks passed
@ConradIrwin
Copy link
Member

Thanks!

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
None yet
Development

Successfully merging this pull request may close these issues.

[vim mode] Bug: going to a mark resets visual seletion
2 participants