Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
vim: implement <space> in normal mode (#7011)
Thorsten Ball7b8bd97652dd
diff --git a/assets/keymaps/vim.json b/assets/keymaps/vim.jsonindex 2b0ad672b0d..bbf132232f2 100644--- a/assets/keymaps/vim.json+++ b/assets/keymaps/vim.json@@ -31,6 +31,7 @@"up": "vim::Up","l": "vim::Right","right": "vim::Right",+ "space": "vim::Space","$": "vim::EndOfLine","^": "vim::FirstNonWhitespace","_": "vim::StartOfLineDownward",diff --git a/crates/editor/src/movement.rs b/crates/editor/src/movement.rsindex f268e926c79..fa5e5f1655c 100644--- a/crates/editor/src/movement.rs+++ b/crates/editor/src/movement.rs@@ -50,11 +50,10 @@ pub fn saturating_left(map: &DisplaySnapshot, mut point: DisplayPoint) -> Displamap.clip_point(point, Bias::Left)}-/// Returns a column to the right of the current point, wrapping-/// to the next line if that point is at the end of line.+/// Returns a column to the right of the current point, doing nothing+// if that point is at the end of the line.pub fn right(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint {- let max_column = map.line_len(point.row());- if point.column() < max_column {+ if point.column() < map.line_len(point.row()) {*point.column_mut() += 1;} else if point.row() < map.max_point().row() {*point.row_mut() += 1;diff --git a/crates/vim/src/motion.rs b/crates/vim/src/motion.rsindex e8cd21bba3d..22800b2e9c1 100644--- a/crates/vim/src/motion.rs+++ b/crates/vim/src/motion.rs@@ -23,6 +23,7 @@ pub enum Motion {Down { display_lines: bool },Up { display_lines: bool },Right,+ Space,NextWordStart { ignore_punctuation: bool },NextWordEnd { ignore_punctuation: bool },PreviousWordStart { ignore_punctuation: bool },@@ -124,6 +125,7 @@ actions!(Left,Backspace,Right,+ Space,CurrentLine,StartOfParagraph,EndOfParagraph,@@ -163,6 +165,7 @@ pub fn register(workspace: &mut Workspace, _: &mut ViewContext<Workspace>) {)});workspace.register_action(|_: &mut Workspace, _: &Right, cx: _| motion(Motion::Right, cx));+ workspace.register_action(|_: &mut Workspace, _: &Space, cx: _| motion(Motion::Space, cx));workspace.register_action(|_: &mut Workspace, action: &FirstNonWhitespace, cx: _| {motion(Motion::FirstNonWhitespace {@@ -306,6 +309,7 @@ impl Motion {| Left| Backspace| Right+ | Space| StartOfLine { .. }| EndOfLineDownward| GoToColumn@@ -332,6 +336,7 @@ impl Motion {| Left| Backspace| Right+ | Space| StartOfLine { .. }| StartOfParagraph| EndOfParagraph@@ -370,6 +375,7 @@ impl Motion {Left| Backspace| Right+ | Space| StartOfLine { .. }| StartOfLineDownward| StartOfParagraph@@ -412,6 +418,7 @@ impl Motion {display_lines: true,} => up_display(map, point, goal, times, &text_layout_details),Right => (right(map, point, times), SelectionGoal::None),+ Space => (space(map, point, times), SelectionGoal::None),NextWordStart { ignore_punctuation } => (next_word_start(map, point, *ignore_punctuation, times),SelectionGoal::None,@@ -614,6 +621,24 @@ fn backspace(map: &DisplaySnapshot, mut point: DisplayPoint, times: usize) -> Dipoint}+fn space(map: &DisplaySnapshot, mut point: DisplayPoint, times: usize) -> DisplayPoint {+ for _ in 0..times {+ point = wrapping_right(map, point);+ }+ point+}++fn wrapping_right(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint {+ let max_column = map.line_len(point.row()).saturating_sub(1);+ if point.column() < max_column {+ *point.column_mut() += 1;+ } else if point.row() < map.max_point().row() {+ *point.row_mut() += 1;+ *point.column_mut() = 0;+ }+ point+}+pub(crate) fn start_of_relative_buffer_row(map: &DisplaySnapshot,point: DisplayPoint,