From ed6bbc7291bdfeb0361f02d0d95151a422108bc2 Mon Sep 17 00:00:00 2001 From: "TechnoHouse (deephbz)" <13776377+deephbz@users.noreply.github.com> Date: Tue, 31 Dec 2024 11:45:43 +0800 Subject: [PATCH 1/2] WIP seems correct --- src/edit_mode/vi/command.rs | 15 +++++++++++++-- src/edit_mode/vi/mod.rs | 5 +++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/edit_mode/vi/command.rs b/src/edit_mode/vi/command.rs index f00b549b..a227a629 100644 --- a/src/edit_mode/vi/command.rs +++ b/src/edit_mode/vi/command.rs @@ -1,4 +1,4 @@ -use super::{motion::Motion, motion::ViCharSearch, parser::ReedlineOption}; +use super::{motion::Motion, motion::ViCharSearch, parser::ReedlineOption, ViMode}; use crate::{EditCommand, ReedlineEvent, Vi}; use std::iter::Peekable; @@ -170,7 +170,18 @@ impl Command { Self::ReplaceChar(c) => { vec![ReedlineOption::Edit(EditCommand::ReplaceChar(*c))] } - Self::SubstituteCharWithInsert => vec![ReedlineOption::Edit(EditCommand::CutChar)], + Self::SubstituteCharWithInsert => { + println!("Command::to_reedline - SubstituteCharWithInsert executing with mode: {:?}", vi_state.mode); + let result = if vi_state.mode == ViMode::Visual { + println!("Command::to_reedline - Executing CutSelection in Visual mode"); + vec![ReedlineOption::Edit(EditCommand::CutSelection)] + } else { + println!("Command::to_reedline - Executing CutChar in Normal mode"); + vec![ReedlineOption::Edit(EditCommand::CutChar)] + }; + println!("Command::to_reedline - Command execution complete"); + result + } Self::HistorySearch => vec![ReedlineOption::Event(ReedlineEvent::SearchHistory)], Self::Switchcase => vec![ReedlineOption::Edit(EditCommand::SwitchcaseChar)], // Whenever a motion is required to finish the command we must be in visual mode diff --git a/src/edit_mode/vi/mod.rs b/src/edit_mode/vi/mod.rs index 81fa5b04..397afc72 100644 --- a/src/edit_mode/vi/mod.rs +++ b/src/edit_mode/vi/mod.rs @@ -89,11 +89,12 @@ impl EditMode for Vi { self.cache.clear(); ReedlineEvent::None } else if res.is_complete(self.mode) { + println!("Vi parse_event - Before command execution: {:?}", self.mode); + let event = res.to_reedline_event(self); if let Some(mode) = res.changes_mode() { + println!("Vi parse_event - Changing mode to: {:?}", mode); self.mode = mode; } - - let event = res.to_reedline_event(self); self.cache.clear(); event } else { From 81dcecb6e96c7a07e737eedc8ce2905ee88af0cc Mon Sep 17 00:00:00 2001 From: "TechnoHouse (deephbz)" <13776377+deephbz@users.noreply.github.com> Date: Tue, 31 Dec 2024 12:06:27 +0800 Subject: [PATCH 2/2] o make key 's', 'd', 'c' and 'x' behave consistently under **visual mode**. Currently 's' and 'd' behave correct but 'c' and 'x' are wrong: - 'x' should cut selection like d under visual mode but it only cut one char under cursor right now - 'c' cut selection correctly but it does not enter insert mode --- src/edit_mode/vi/command.rs | 8 +++++++- src/edit_mode/vi/parser.rs | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/edit_mode/vi/command.rs b/src/edit_mode/vi/command.rs index a227a629..c7b7548a 100644 --- a/src/edit_mode/vi/command.rs +++ b/src/edit_mode/vi/command.rs @@ -166,7 +166,13 @@ impl Command { select: false, })], Self::RewriteCurrentLine => vec![ReedlineOption::Edit(EditCommand::CutCurrentLine)], - Self::DeleteChar => vec![ReedlineOption::Edit(EditCommand::CutChar)], + Self::DeleteChar => { + if vi_state.mode == ViMode::Visual { + vec![ReedlineOption::Edit(EditCommand::CutSelection)] + } else { + vec![ReedlineOption::Edit(EditCommand::CutChar)] + } + } Self::ReplaceChar(c) => { vec![ReedlineOption::Edit(EditCommand::ReplaceChar(*c))] } diff --git a/src/edit_mode/vi/parser.rs b/src/edit_mode/vi/parser.rs index 0699dbc1..d598c019 100644 --- a/src/edit_mode/vi/parser.rs +++ b/src/edit_mode/vi/parser.rs @@ -108,7 +108,8 @@ impl ParsedViSequence { | (Some(Command::RewriteCurrentLine), ParseResult::Incomplete) | (Some(Command::SubstituteCharWithInsert), ParseResult::Incomplete) | (Some(Command::HistorySearch), ParseResult::Incomplete) - | (Some(Command::Change), ParseResult::Valid(_)) => Some(ViMode::Insert), + | (Some(Command::Change), ParseResult::Valid(_)) + | (Some(Command::Change), ParseResult::Incomplete) => Some(ViMode::Insert), (Some(Command::ChangeInside(char)), ParseResult::Incomplete) if is_valid_change_inside_left(char) || is_valid_change_inside_right(char) => {