Fix substitute in visual line mode
This commit is contained in:
parent
e3788cc6e6
commit
236b755b1d
1 changed files with 26 additions and 0 deletions
|
@ -4,6 +4,7 @@ use language::Point;
|
||||||
use crate::{motion::Motion, Mode, Vim};
|
use crate::{motion::Motion, Mode, Vim};
|
||||||
|
|
||||||
pub fn substitute(vim: &mut Vim, count: Option<usize>, cx: &mut WindowContext) {
|
pub fn substitute(vim: &mut Vim, count: Option<usize>, cx: &mut WindowContext) {
|
||||||
|
let line_mode = vim.state.mode == Mode::Visual { line: true };
|
||||||
vim.switch_mode(Mode::Insert, true, cx);
|
vim.switch_mode(Mode::Insert, true, cx);
|
||||||
vim.update_active_editor(cx, |editor, cx| {
|
vim.update_active_editor(cx, |editor, cx| {
|
||||||
editor.transact(cx, |editor, cx| {
|
editor.transact(cx, |editor, cx| {
|
||||||
|
@ -12,6 +13,17 @@ pub fn substitute(vim: &mut Vim, count: Option<usize>, cx: &mut WindowContext) {
|
||||||
if selection.start == selection.end {
|
if selection.start == selection.end {
|
||||||
Motion::Right.expand_selection(map, selection, count, true);
|
Motion::Right.expand_selection(map, selection, count, true);
|
||||||
}
|
}
|
||||||
|
if line_mode {
|
||||||
|
Motion::CurrentLine.expand_selection(map, selection, None, false);
|
||||||
|
if let Some((point, _)) = Motion::FirstNonWhitespace.move_point(
|
||||||
|
map,
|
||||||
|
selection.start,
|
||||||
|
selection.goal,
|
||||||
|
None,
|
||||||
|
) {
|
||||||
|
selection.start = point;
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
let selections = editor.selections.all::<Point>(cx);
|
let selections = editor.selections.all::<Point>(cx);
|
||||||
|
@ -67,5 +79,19 @@ mod test {
|
||||||
// should transactionally undo selection changes
|
// should transactionally undo selection changes
|
||||||
cx.simulate_keystrokes(["escape", "u"]);
|
cx.simulate_keystrokes(["escape", "u"]);
|
||||||
cx.assert_editor_state("ˇcàfé\n");
|
cx.assert_editor_state("ˇcàfé\n");
|
||||||
|
|
||||||
|
// it handles visual line mode
|
||||||
|
cx.set_state(
|
||||||
|
indoc! {"
|
||||||
|
alpha
|
||||||
|
beˇta
|
||||||
|
gamma"},
|
||||||
|
Mode::Normal,
|
||||||
|
);
|
||||||
|
cx.simulate_keystrokes(["shift-v", "s"]);
|
||||||
|
cx.assert_editor_state(indoc! {"
|
||||||
|
alpha
|
||||||
|
ˇ
|
||||||
|
gamma"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue