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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions crates/vim/src/normal/mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Vim {
_ => self.marks.get(&*text).cloned(),
};

let Some(anchors) = anchors else { return };
let Some(mut anchors) = anchors else { return };

let is_active_operator = self.active_operator().is_some();
if is_active_operator {
Expand All @@ -120,6 +120,12 @@ impl Vim {
)
}
} else {
// Save the last anchor so as to jump to it later.
let anchor: Option<Anchor> = anchors.last_mut().map(|anchor| *anchor);
let should_jump = self.mode == Mode::Visual
|| self.mode == Mode::VisualLine
|| self.mode == Mode::VisualBlock;

self.update_editor(window, cx, |_, editor, window, cx| {
let map = editor.snapshot(window, cx);
let mut ranges: Vec<Range<Anchor>> = Vec::new();
Expand All @@ -132,14 +138,24 @@ impl Vim {
.buffer_snapshot
.anchor_before(point.to_point(&map.display_snapshot));
}

if ranges.last() != Some(&(anchor..anchor)) {
ranges.push(anchor..anchor);
}
}
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
s.select_anchor_ranges(ranges)
})

if !should_jump {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
s.select_anchor_ranges(ranges)
});
}
});

if should_jump {
if let Some(anchor) = anchor {
self.motion(Motion::Jump { anchor, line }, window, cx)
}
}
}
}
}
Expand Down
Loading