Skip to content

Commit

Permalink
Update switch_to to ignore requests for the current mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacdonald committed Mar 5, 2024
1 parent 1cb8fc2 commit 733fbd1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/models/application/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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));
}
}

0 comments on commit 733fbd1

Please sign in to comment.