Skip to content

Commit

Permalink
Cleanup: cargo fmt --all
Browse files Browse the repository at this point in the history
  • Loading branch information
adaschma committed Jun 15, 2024
1 parent 2c6fcce commit f507e2f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/edit_mode/vi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand All @@ -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),
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/edit_mode/vi/motion.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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![]
}
Expand Down
31 changes: 16 additions & 15 deletions src/edit_mode/vi/parser.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -92,22 +96,19 @@ impl ParsedViSequence {
}
}

pub fn changes_mode(&self) -> Option<ViMode>{
pub fn changes_mode(&self) -> Option<ViMode> {
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,
}
}

Expand Down

0 comments on commit f507e2f

Please sign in to comment.