Skip to content

Commit

Permalink
fix Vi mode change: follow-up: Change/Delete + Incomplete motion coul…
Browse files Browse the repository at this point in the history
…d yield mode change from visual to insert/normal
  • Loading branch information
deephbz committed Jan 1, 2025
1 parent 980355d commit 57c2128
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/edit_mode/vi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
19 changes: 9 additions & 10 deletions src/edit_mode/vi/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl ParsedViSequence {
}
}

pub fn changes_mode(&self) -> Option<ViMode> {
pub fn changes_mode(&self, mode: ViMode) -> Option<ViMode> {
match (&self.command, &self.motion) {
(Some(Command::EnterViInsert), ParseResult::Incomplete)
| (Some(Command::EnterViAppend), ParseResult::Incomplete)
Expand All @@ -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,
}
}
Expand Down

0 comments on commit 57c2128

Please sign in to comment.