Skip to content

Commit

Permalink
fix: add check before switching input mode in Event::CommandUpdate ha…
Browse files Browse the repository at this point in the history
…ndler

Wrapped mode switch logic into try_switch_between_normal_and_locked_mode
function. Updated Event::CommandUpdate handler to use the new function
to fix the bug.
  • Loading branch information
WingsZeng committed Dec 12, 2024
1 parent 2a74462 commit 7cb1b5b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ impl ZellijPlugin for State {
if pipe_message.name == "Event::CommandUpdate" {
if let Some(cmdline) = pipe_message.payload {
if let Some(program) = parse_program_from_cmdline(&cmdline) {
switch_to_input_mode(&self.get_default_input_mode_by_program(program));
self.try_switch_between_normal_and_locked_mode(
&self.get_default_input_mode_by_program(program),
);
}
};
}
Expand Down Expand Up @@ -124,9 +126,7 @@ impl State {
}
if Some(focused_pane_id) != self.focused_pane_id {
if let Some(input_mode) = self.pane_mode_map.get(&focused_pane_id) {
if self.is_in_normal_or_locked_mode() {
switch_to_input_mode(input_mode);
}
self.try_switch_between_normal_and_locked_mode(input_mode);
}
self.focused_pane_id = Some(focused_pane_id);
}
Expand All @@ -136,6 +136,12 @@ impl State {
fn is_in_normal_or_locked_mode(&self) -> bool {
self.input_mode == InputMode::Normal || self.input_mode == InputMode::Locked
}

fn try_switch_between_normal_and_locked_mode(&self, mode: &InputMode) {
if self.is_in_normal_or_locked_mode() && self.input_mode != *mode {
switch_to_input_mode(mode);
}
}
}

fn parse_program_from_cmdline(cmdline: &str) -> Option<&str> {
Expand Down

0 comments on commit 7cb1b5b

Please sign in to comment.