From 02f551d42eeda2f277cb98416bb035529b2a91aa Mon Sep 17 00:00:00 2001 From: andreistan26 <48967297+andreistan26@users.noreply.github.com> Date: Fri, 9 Feb 2024 23:53:44 +0200 Subject: [PATCH] Move left when exiting insert mode (#699) Signed-off-by: Andrei Stan --- src/edit_mode/vi/mod.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/edit_mode/vi/mod.rs b/src/edit_mode/vi/mod.rs index 4428c645..c687a86b 100644 --- a/src/edit_mode/vi/mod.rs +++ b/src/edit_mode/vi/mod.rs @@ -136,8 +136,17 @@ impl EditMode for Vi { } (_, KeyModifiers::NONE, KeyCode::Esc) => { self.cache.clear(); - self.mode = ViMode::Normal; - ReedlineEvent::Multiple(vec![ReedlineEvent::Esc, ReedlineEvent::Repaint]) + + ReedlineEvent::Multiple(vec![ + if self.mode == ViMode::Insert { + self.mode = ViMode::Normal; + ReedlineEvent::Left + } else { + ReedlineEvent::None + }, + ReedlineEvent::Esc, + ReedlineEvent::Repaint, + ]) } (_, KeyModifiers::NONE, KeyCode::Enter) => { self.mode = ViMode::Insert; @@ -188,7 +197,11 @@ mod test { assert_eq!( result, - ReedlineEvent::Multiple(vec![ReedlineEvent::Esc, ReedlineEvent::Repaint]) + ReedlineEvent::Multiple(vec![ + ReedlineEvent::Left, + ReedlineEvent::Esc, + ReedlineEvent::Repaint + ]) ); assert!(matches!(vi.mode, ViMode::Normal)); }