Preserve line mode selection on undo

This diverges from vim's behaviour (which collapses the
cursor to a single point on undo).
This commit is contained in:
Conrad Irwin 2023-08-17 15:40:27 -06:00
parent 59d1a5632f
commit eb0b2e60bb

View File

@ -18,7 +18,7 @@ use gpui::{
actions, impl_actions, keymap_matcher::KeymapContext, keymap_matcher::MatchResult, AppContext, actions, impl_actions, keymap_matcher::KeymapContext, keymap_matcher::MatchResult, AppContext,
Subscription, ViewContext, ViewHandle, WeakViewHandle, WindowContext, Subscription, ViewContext, ViewHandle, WeakViewHandle, WindowContext,
}; };
use language::CursorShape; use language::{CursorShape, Selection, SelectionGoal};
pub use mode_indicator::ModeIndicator; pub use mode_indicator::ModeIndicator;
use motion::Motion; use motion::Motion;
use normal::normal_replace; use normal::normal_replace;
@ -150,8 +150,8 @@ impl Vim {
Event::SelectionsChanged { local: true } => { Event::SelectionsChanged { local: true } => {
let editor = editor.read(cx); let editor = editor.read(cx);
if editor.leader_replica_id().is_none() { if editor.leader_replica_id().is_none() {
let newest_empty = editor.selections.newest::<usize>(cx).is_empty(); let newest = editor.selections.newest::<usize>(cx);
local_selections_changed(newest_empty, cx); local_selections_changed(newest, cx);
} }
} }
Event::InputIgnored { text } => { Event::InputIgnored { text } => {
@ -427,10 +427,14 @@ impl Setting for VimModeSetting {
} }
} }
fn local_selections_changed(newest_empty: bool, cx: &mut WindowContext) { fn local_selections_changed(newest: Selection<usize>, cx: &mut WindowContext) {
Vim::update(cx, |vim, cx| { Vim::update(cx, |vim, cx| {
if vim.enabled && vim.state().mode == Mode::Normal && !newest_empty { if vim.enabled && vim.state().mode == Mode::Normal && !newest.is_empty() {
vim.switch_mode(Mode::Visual, false, cx) if matches!(newest.goal, SelectionGoal::ColumnRange { .. }) {
vim.switch_mode(Mode::VisualBlock, false, cx);
} else {
vim.switch_mode(Mode::Visual, false, cx)
}
} }
}) })
} }