From 9d42d75bff299f78032450cfd55a96b2c76c448c Mon Sep 17 00:00:00 2001 From: gwenn Date: Sat, 20 Aug 2022 19:00:16 +0200 Subject: [PATCH] Fix ViFirstPrint movement when there is no whitespace at the beginining of line. --- src/command.rs | 4 +++- src/test/vi_cmd.rs | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/command.rs b/src/command.rs index c16f9669f9..652e9f1c0d 100644 --- a/src/command.rs +++ b/src/command.rs @@ -51,7 +51,9 @@ pub fn execute( } Cmd::Move(Movement::ViFirstPrint) => { s.edit_move_home()?; - s.edit_move_to_next_word(At::Start, Word::Big, 1)?; + if s.line.starts_with(char::is_whitespace) { + s.edit_move_to_next_word(At::Start, Word::Big, 1)?; + } } Cmd::Move(Movement::BackwardChar(n)) => { // Move back a character. diff --git a/src/test/vi_cmd.rs b/src/test/vi_cmd.rs index be8437d2dc..c8ff89b2fe 100644 --- a/src/test/vi_cmd.rs +++ b/src/test/vi_cmd.rs @@ -58,6 +58,16 @@ fn caret() { ); } +#[test] +fn caret_no_whitespace() { + assert_cursor( + EditMode::Vi, + ("Hi", ""), + &[E::ESC, E::from('^'), E::ENTER], + ("", "Hi"), + ); +} + #[test] fn a() { assert_cursor(