From 57c2128ed1f8d97258fb9fa0de041d21c8ffc5d5 Mon Sep 17 00:00:00 2001 From: "TechnoHouse (deephbz)" <13776377+deephbz@users.noreply.github.com> Date: Wed, 1 Jan 2025 10:19:28 +0800 Subject: [PATCH] fix Vi mode change: follow-up: Change/Delete + Incomplete motion could yield mode change from visual to insert/normal --- src/edit_mode/vi/mod.rs | 2 +- src/edit_mode/vi/parser.rs | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/edit_mode/vi/mod.rs b/src/edit_mode/vi/mod.rs index 806a19c6..cc19cbd6 100644 --- a/src/edit_mode/vi/mod.rs +++ b/src/edit_mode/vi/mod.rs @@ -90,7 +90,7 @@ impl EditMode for Vi { ReedlineEvent::None } else if res.is_complete(self.mode) { let event = res.to_reedline_event(self); - if let Some(mode) = res.changes_mode() { + if let Some(mode) = res.changes_mode(self.mode) { self.mode = mode; } self.cache.clear(); diff --git a/src/edit_mode/vi/parser.rs b/src/edit_mode/vi/parser.rs index 9a9c79ba..71ce2b1a 100644 --- a/src/edit_mode/vi/parser.rs +++ b/src/edit_mode/vi/parser.rs @@ -98,7 +98,7 @@ impl ParsedViSequence { } } - pub fn changes_mode(&self) -> Option { + pub fn changes_mode(&self, mode: ViMode) -> Option { match (&self.command, &self.motion) { (Some(Command::EnterViInsert), ParseResult::Incomplete) | (Some(Command::EnterViAppend), ParseResult::Incomplete) @@ -108,19 +108,18 @@ impl ParsedViSequence { | (Some(Command::RewriteCurrentLine), ParseResult::Incomplete) | (Some(Command::SubstituteCharWithInsert), ParseResult::Incomplete) | (Some(Command::HistorySearch), ParseResult::Incomplete) - | (Some(Command::Change), ParseResult::Valid(_)) - | (Some(Command::Change), ParseResult::Incomplete) => Some(ViMode::Insert), - (Some(Command::ChangeInside(char)), ParseResult::Incomplete) + | (Some(Command::Change), ParseResult::Valid(_)) => Some(ViMode::Insert), + (Some(Command::Change), ParseResult::Incomplete) if mode == ViMode::Visual => { + Some(ViMode::Insert) + } + (Some(Command::Delete), ParseResult::Incomplete) if mode == ViMode::Visual => { + Some(ViMode::Normal) + } + (Some(Command::ChangeInside(char)), ParseResult::Valid(_)) if is_valid_change_inside_left(char) || is_valid_change_inside_right(char) => { Some(ViMode::Insert) } - (Some(Command::Delete), ParseResult::Incomplete) - | (Some(Command::DeleteChar), ParseResult::Incomplete) - | (Some(Command::DeleteToEnd), ParseResult::Incomplete) - | (Some(Command::Delete), ParseResult::Valid(_)) - | (Some(Command::DeleteChar), ParseResult::Valid(_)) - | (Some(Command::DeleteToEnd), ParseResult::Valid(_)) => Some(ViMode::Normal), _ => None, } }