Add a VisualBlock mode

Instead of trying to extend the Mode::Visual special case, just split
out into three different modes.
This commit is contained in:
Conrad Irwin 2023-08-15 08:48:01 -06:00
parent 404b1aa65a
commit 1cc0798aea
16 changed files with 94 additions and 90 deletions

View file

@ -14,14 +14,14 @@ pub fn change_case(_: &mut Workspace, _: &ChangeCase, cx: &mut ViewContext<Works
let snapshot = editor.buffer().read(cx).snapshot(cx);
for selection in editor.selections.all::<Point>(cx) {
match vim.state.mode {
Mode::Visual { line: true } => {
Mode::VisualLine => {
let start = Point::new(selection.start.row, 0);
let end =
Point::new(selection.end.row, snapshot.line_len(selection.end.row));
ranges.push(start..end);
cursor_positions.push(start..start);
}
Mode::Visual { line: false } => {
Mode::Visual | Mode::VisualBlock => {
ranges.push(selection.start..selection.end);
cursor_positions.push(selection.start..selection.start);
}

View file

@ -4,7 +4,7 @@ use language::Point;
use crate::{motion::Motion, utils::copy_selections_content, Mode, Vim};
pub fn substitute(vim: &mut Vim, count: Option<usize>, cx: &mut WindowContext) {
let line_mode = vim.state.mode == Mode::Visual { line: true };
let line_mode = vim.state.mode == Mode::VisualLine;
vim.switch_mode(Mode::Insert, true, cx);
vim.update_active_editor(cx, |editor, cx| {
editor.transact(cx, |editor, cx| {
@ -52,7 +52,7 @@ mod test {
cx.assert_editor_state("xˇbc\n");
// supports a selection
cx.set_state(indoc! {"a«bcˇ»\n"}, Mode::Visual { line: false });
cx.set_state(indoc! {"a«bcˇ»\n"}, Mode::Visual);
cx.assert_editor_state("a«bcˇ»\n");
cx.simulate_keystrokes(["s", "x"]);
cx.assert_editor_state("axˇ\n");