diff --git a/src/edit_mode/vi/mod.rs b/src/edit_mode/vi/mod.rs index afa13695..7c7601d1 100644 --- a/src/edit_mode/vi/mod.rs +++ b/src/edit_mode/vi/mod.rs @@ -68,7 +68,7 @@ impl EditMode for Vi { self.mode = ViMode::Visual; ReedlineEvent::Multiple(vec![ReedlineEvent::Esc, ReedlineEvent::Repaint]) } - (ViMode::Normal|ViMode::Visual, modifier, KeyCode::Char(c)) => { + (ViMode::Normal | ViMode::Visual, modifier, KeyCode::Char(c)) => { let c = c.to_ascii_lowercase(); if let Some(event) = self @@ -149,7 +149,7 @@ impl EditMode for Vi { self.mode = ViMode::Insert; ReedlineEvent::Enter } - (ViMode::Normal|ViMode::Visual, _, _) => self + (ViMode::Normal | ViMode::Visual, _, _) => self .normal_keybindings .find_binding(modifiers, code) .unwrap_or(ReedlineEvent::None), @@ -171,7 +171,7 @@ impl EditMode for Vi { fn edit_mode(&self) -> PromptEditMode { match self.mode { - ViMode::Normal|ViMode::Visual => PromptEditMode::Vi(PromptViMode::Normal), + ViMode::Normal | ViMode::Visual => PromptEditMode::Vi(PromptViMode::Normal), ViMode::Insert => PromptEditMode::Vi(PromptViMode::Insert), } } diff --git a/src/edit_mode/vi/motion.rs b/src/edit_mode/vi/motion.rs index 1de09002..a0e1ad3c 100644 --- a/src/edit_mode/vi/motion.rs +++ b/src/edit_mode/vi/motion.rs @@ -1,6 +1,6 @@ use std::iter::Peekable; -use crate::{EditCommand, ReedlineEvent, Vi, edit_mode::vi::ViMode}; +use crate::{edit_mode::vi::ViMode, EditCommand, ReedlineEvent, Vi}; use super::parser::{ParseResult, ReedlineOption}; @@ -146,12 +146,16 @@ impl Motion { match self { Motion::Left => vec![ReedlineOption::Event(ReedlineEvent::UntilFound(vec![ ReedlineEvent::MenuLeft, - ReedlineEvent::Edit(vec![EditCommand::MoveLeft { select: select_mode, }]) + ReedlineEvent::Edit(vec![EditCommand::MoveLeft { + select: select_mode, + }]), ]))], Motion::Right => vec![ReedlineOption::Event(ReedlineEvent::UntilFound(vec![ ReedlineEvent::HistoryHintComplete, ReedlineEvent::MenuRight, - ReedlineEvent::Edit(vec![EditCommand::MoveRight { select: select_mode, }]), + ReedlineEvent::Edit(vec![EditCommand::MoveRight { + select: select_mode, + }]), ]))], Motion::Up => vec![ReedlineOption::Event(ReedlineEvent::UntilFound(vec![ ReedlineEvent::MenuUp, @@ -227,7 +231,9 @@ impl Motion { } Motion::ReverseCharSearch => { if let Some(char_search) = vi_state.last_char_search.as_ref() { - vec![ReedlineOption::Edit(char_search.reverse().to_move(select_mode))] + vec![ReedlineOption::Edit( + char_search.reverse().to_move(select_mode), + )] } else { vec![] } diff --git a/src/edit_mode/vi/parser.rs b/src/edit_mode/vi/parser.rs index e4b53772..7e1c350f 100644 --- a/src/edit_mode/vi/parser.rs +++ b/src/edit_mode/vi/parser.rs @@ -1,6 +1,6 @@ use super::command::{parse_command, Command}; use super::motion::{parse_motion, Motion}; -use crate::{EditCommand, ReedlineEvent, Vi, edit_mode::vi::ViMode}; +use crate::{edit_mode::vi::ViMode, EditCommand, ReedlineEvent, Vi}; use std::iter::Peekable; #[derive(Debug, Clone)] @@ -55,7 +55,11 @@ impl ParsedViSequence { match (&self.command, &self.motion) { (None, ParseResult::Valid(_)) => true, (Some(Command::Incomplete), _) => false, - (Some(cmd), ParseResult::Incomplete) if !cmd.requires_motion() || mode == ViMode::Visual => true, + (Some(cmd), ParseResult::Incomplete) + if !cmd.requires_motion() || mode == ViMode::Visual => + { + true + } (Some(_), ParseResult::Valid(_)) => true, (Some(cmd), ParseResult::Incomplete) if cmd.requires_motion() => false, _ => false, @@ -92,22 +96,19 @@ impl ParsedViSequence { } } - pub fn changes_mode(&self) -> Option{ + pub fn changes_mode(&self) -> Option { match (&self.command, &self.motion) { (Some(Command::EnterViInsert), ParseResult::Incomplete) - | (Some(Command::EnterViAppend), ParseResult::Incomplete) - | (Some(Command::ChangeToLineEnd), ParseResult::Incomplete) - | (Some(Command::AppendToEnd), ParseResult::Incomplete) - | (Some(Command::PrependToStart), ParseResult::Incomplete) - | (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::EnterViAppend), ParseResult::Incomplete) + | (Some(Command::ChangeToLineEnd), ParseResult::Incomplete) + | (Some(Command::AppendToEnd), ParseResult::Incomplete) + | (Some(Command::PrependToStart), ParseResult::Incomplete) + | (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::Delete), ParseResult::Incomplete) => Some(ViMode::Normal), - _ => None + _ => None, } }