From 72f6b502d1bf544a2087f960e08a00af5d1e63a4 Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Thu, 31 Oct 2024 16:49:48 +0100 Subject: [PATCH] fix(ux): forward keys to pane in locked mode and base mode rather than hard-coded normal mode (#3715) * fix(keybindings): only forward clear keys in locked mode and default mode * style(fmt): rustfmt --- zellij-server/src/lib.rs | 18 ++++++++++++++++-- zellij-server/src/route.rs | 3 ++- zellij-utils/src/input/keybinds.rs | 8 +++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index 19ac8a66..a4daf6f9 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -203,6 +203,13 @@ impl SessionConfiguration { .map(|c| c.keybinds.clone()) .unwrap_or_default() } + pub fn get_client_default_input_mode(&self, client_id: &ClientId) -> InputMode { + self.runtime_config + .get(client_id) + .or_else(|| self.saved_config.get(client_id)) + .and_then(|c| c.options.default_mode.clone()) + .unwrap_or_default() + } pub fn get_client_configuration(&self, client_id: &ClientId) -> Config { self.runtime_config .get(client_id) @@ -307,10 +314,17 @@ impl SessionMetaData { pub fn get_client_keybinds_and_mode( &self, client_id: &ClientId, - ) -> Option<(Keybinds, &InputMode)> { + ) -> Option<(Keybinds, &InputMode, InputMode)> { + // (keybinds, current_input_mode, + // default_input_mode) let client_keybinds = self.session_configuration.get_client_keybinds(client_id); + let default_input_mode = self + .session_configuration + .get_client_default_input_mode(client_id); match self.current_input_modes.get(client_id) { - Some(client_input_mode) => Some((client_keybinds, client_input_mode)), + Some(client_input_mode) => { + Some((client_keybinds, client_input_mode, default_input_mode)) + }, _ => None, } } diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs index b0f5cce6..cd21140d 100644 --- a/zellij-server/src/route.rs +++ b/zellij-server/src/route.rs @@ -1015,12 +1015,13 @@ pub(crate) fn route_thread_main( ClientToServerMsg::Key(key, raw_bytes, is_kitty_keyboard_protocol) => { if let Some(rlocked_sessions) = rlocked_sessions.as_ref() { match rlocked_sessions.get_client_keybinds_and_mode(&client_id) { - Some((keybinds, input_mode)) => { + Some((keybinds, input_mode, default_input_mode)) => { for action in keybinds .get_actions_for_key_in_mode_or_default_action( &input_mode, &key, raw_bytes, + default_input_mode, is_kitty_keyboard_protocol, ) { diff --git a/zellij-utils/src/input/keybinds.rs b/zellij-utils/src/input/keybinds.rs index af923056..99ec0992 100644 --- a/zellij-utils/src/input/keybinds.rs +++ b/zellij-utils/src/input/keybinds.rs @@ -39,6 +39,7 @@ impl Keybinds { mode: &InputMode, key_with_modifier: &KeyWithModifier, raw_bytes: Vec, + default_input_mode: InputMode, key_is_kitty_protocol: bool, ) -> Vec { self.0 @@ -50,6 +51,7 @@ impl Keybinds { mode, Some(key_with_modifier), raw_bytes, + default_input_mode, key_is_kitty_protocol, )] }) @@ -65,10 +67,14 @@ impl Keybinds { mode: &InputMode, key_with_modifier: Option<&KeyWithModifier>, raw_bytes: Vec, + default_input_mode: InputMode, key_is_kitty_protocol: bool, ) -> Action { match *mode { - InputMode::Normal | InputMode::Locked => { + InputMode::Locked => { + Action::Write(key_with_modifier.cloned(), raw_bytes, key_is_kitty_protocol) + }, + mode if mode == default_input_mode => { Action::Write(key_with_modifier.cloned(), raw_bytes, key_is_kitty_protocol) }, InputMode::RenameTab => Action::TabNameInput(raw_bytes),