From 660f43c501219eeb6f64c8d9fefab2ea20a1052f Mon Sep 17 00:00:00 2001 From: dinocosta Date: Thu, 20 Feb 2025 10:18:10 +0000 Subject: [PATCH] fix(vim): only use jump motion if 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. --- crates/vim/src/normal/mark.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/crates/vim/src/normal/mark.rs b/crates/vim/src/normal/mark.rs index 6fdd789cfe7ee4..7040d55afd116c 100644 --- a/crates/vim/src/normal/mark.rs +++ b/crates/vim/src/normal/mark.rs @@ -122,8 +122,11 @@ impl Vim { } else { // Save the last anchor so as to jump to it later. let anchor: Option = anchors.last_mut().map(|last| last.clone()); + let should_jump = self.mode == Mode::Visual + || self.mode == Mode::VisualLine + || self.mode == Mode::VisualBlock; - self.update_editor(window, cx, |vim, editor, window, cx| { + self.update_editor(window, cx, |_, editor, window, cx| { let map = editor.snapshot(window, cx); let mut ranges: Vec> = Vec::new(); for mut anchor in anchors { @@ -141,18 +144,22 @@ impl Vim { } } - if vim.mode != Mode::Visual - && vim.mode != Mode::VisualLine - && vim.mode != Mode::VisualBlock - { + if !should_jump { editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_anchor_ranges(ranges) }); } }); - if let Some(anchor) = anchor { - self.motion(Motion::Jump { anchor, line }, window, cx) + if should_jump && anchor.is_some() { + self.motion( + Motion::Jump { + anchor: anchor.unwrap(), + line, + }, + window, + cx, + ) } } }