Skip to content

Commit

Permalink
fix(vim): only use jump motion if in visual mode
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dinocosta committed Feb 20, 2025
1 parent 1d7761c commit 660f43c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions crates/vim/src/normal/mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,11 @@ impl Vim {
} else {
// Save the last anchor so as to jump to it later.
let anchor: Option<Anchor> = 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<Range<Anchor>> = Vec::new();
for mut anchor in anchors {
Expand All @@ -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,
)
}
}
}
Expand Down

0 comments on commit 660f43c

Please sign in to comment.