Skip to content

Commit

Permalink
EditCommand::StopCutting (fixes tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
alsuren committed Sep 16, 2023
1 parent b51e5d7 commit 30c78ea
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/core_editor/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ impl Editor {
EditCommand::CutLeftBefore(c) => self.cut_left_until_char(*c, true, true),
EditCommand::MoveLeftUntil(c) => self.move_left_until_char(*c, false, true),
EditCommand::MoveLeftBefore(c) => self.move_left_until_char(*c, true, true),
EditCommand::StopCutting => self.last_cut_command = LastCutCommand::BeforeLast,
}

self.last_cut_command = match self.last_cut_command {
Expand Down
18 changes: 16 additions & 2 deletions src/edit_mode/vi/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ impl ParsedViSequence {
}
}

fn add_stop_cutting_event(event: ReedlineEvent) -> ReedlineEvent {
match event {
ReedlineEvent::Edit(mut edits) => {
edits.push(EditCommand::StopCutting);
ReedlineEvent::Edit(edits)
}
ReedlineEvent::Multiple(mut edits) => {
edits.push(ReedlineEvent::Edit(vec![EditCommand::StopCutting]));
ReedlineEvent::Multiple(edits)
}
_ => event,
}
}

pub fn enters_insert_mode(&self) -> bool {
matches!(
(&self.command, &self.motion),
Expand All @@ -117,7 +131,7 @@ impl ParsedViSequence {
ReedlineEvent::None => {}
event => vi_state.previous = Some(event.clone()),
}
events
Self::add_stop_cutting_event(events)
}
// This case handles all combinations of commands and motions that could exist
(_, Some(command), _, ParseResult::Valid(motion)) => {
Expand All @@ -127,7 +141,7 @@ impl ParsedViSequence {
ReedlineEvent::None => {}
event => vi_state.previous = Some(event.clone()),
}
events
Self::add_stop_cutting_event(events)
}
(_, None, _, ParseResult::Valid(motion)) => {
self.apply_multiplier(Some(motion.to_reedline(vi_state)))
Expand Down
7 changes: 6 additions & 1 deletion src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ pub enum EditCommand {

/// CutUntil left before char
MoveLeftBefore(char),

/// Stop emacs-style cut buffer growth. Next cut command will make a new cut buffer.
StopCutting,
}

impl Display for EditCommand {
Expand Down Expand Up @@ -250,6 +253,7 @@ impl Display for EditCommand {
EditCommand::CutLeftBefore(_) => write!(f, "CutLeftBefore Value: <char>"),
EditCommand::MoveLeftUntil(_) => write!(f, "MoveLeftUntil Value: <char>"),
EditCommand::MoveLeftBefore(_) => write!(f, "MoveLeftBefore Value: <char>"),
EditCommand::StopCutting => write!(f, "StopCutting"),
}
}
}
Expand Down Expand Up @@ -277,7 +281,8 @@ impl EditCommand {
| EditCommand::MoveRightUntil(_)
| EditCommand::MoveRightBefore(_)
| EditCommand::MoveLeftUntil(_)
| EditCommand::MoveLeftBefore(_) => EditType::MoveCursor,
| EditCommand::MoveLeftBefore(_)
| EditCommand::StopCutting => EditType::MoveCursor,

// Text edits
EditCommand::InsertChar(_)
Expand Down

0 comments on commit 30c78ea

Please sign in to comment.