diff --git a/src/models/application/mod.rs b/src/models/application/mod.rs index f7a8f469..48b5dc96 100644 --- a/src/models/application/mod.rs +++ b/src/models/application/mod.rs @@ -226,6 +226,10 @@ impl Application { } pub fn switch_to(&mut self, mode_key: ModeKey) { + if self.current_mode == mode_key { + return; + } + // Check out the specified mode. let mut mode = self.modes.remove(&mode_key).unwrap(); @@ -528,4 +532,19 @@ mod tests { assert_eq!(app.current_mode, ModeKey::Insert); assert!(matches!(app.mode, Mode::Insert)); } + + #[test] + fn switch_to_handles_switching_to_current_mode() { + let mut app = Application::new(&Vec::new()).unwrap(); + + app.switch_to(ModeKey::Insert); + + assert_eq!(app.current_mode, ModeKey::Insert); + assert!(matches!(app.mode, Mode::Insert)); + + app.switch_to(ModeKey::Insert); + + assert_eq!(app.current_mode, ModeKey::Insert); + assert!(matches!(app.mode, Mode::Insert)); + } }