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
This commit is contained in:
Aram Drevekenin 2024-10-31 16:49:48 +01:00 committed by GitHub
parent 96d3113fa4
commit 72f6b502d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 4 deletions

View file

@ -203,6 +203,13 @@ impl SessionConfiguration {
.map(|c| c.keybinds.clone()) .map(|c| c.keybinds.clone())
.unwrap_or_default() .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 { pub fn get_client_configuration(&self, client_id: &ClientId) -> Config {
self.runtime_config self.runtime_config
.get(client_id) .get(client_id)
@ -307,10 +314,17 @@ impl SessionMetaData {
pub fn get_client_keybinds_and_mode( pub fn get_client_keybinds_and_mode(
&self, &self,
client_id: &ClientId, 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 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) { 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, _ => None,
} }
} }

View file

@ -1015,12 +1015,13 @@ pub(crate) fn route_thread_main(
ClientToServerMsg::Key(key, raw_bytes, is_kitty_keyboard_protocol) => { ClientToServerMsg::Key(key, raw_bytes, is_kitty_keyboard_protocol) => {
if let Some(rlocked_sessions) = rlocked_sessions.as_ref() { if let Some(rlocked_sessions) = rlocked_sessions.as_ref() {
match rlocked_sessions.get_client_keybinds_and_mode(&client_id) { 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 for action in keybinds
.get_actions_for_key_in_mode_or_default_action( .get_actions_for_key_in_mode_or_default_action(
&input_mode, &input_mode,
&key, &key,
raw_bytes, raw_bytes,
default_input_mode,
is_kitty_keyboard_protocol, is_kitty_keyboard_protocol,
) )
{ {

View file

@ -39,6 +39,7 @@ impl Keybinds {
mode: &InputMode, mode: &InputMode,
key_with_modifier: &KeyWithModifier, key_with_modifier: &KeyWithModifier,
raw_bytes: Vec<u8>, raw_bytes: Vec<u8>,
default_input_mode: InputMode,
key_is_kitty_protocol: bool, key_is_kitty_protocol: bool,
) -> Vec<Action> { ) -> Vec<Action> {
self.0 self.0
@ -50,6 +51,7 @@ impl Keybinds {
mode, mode,
Some(key_with_modifier), Some(key_with_modifier),
raw_bytes, raw_bytes,
default_input_mode,
key_is_kitty_protocol, key_is_kitty_protocol,
)] )]
}) })
@ -65,10 +67,14 @@ impl Keybinds {
mode: &InputMode, mode: &InputMode,
key_with_modifier: Option<&KeyWithModifier>, key_with_modifier: Option<&KeyWithModifier>,
raw_bytes: Vec<u8>, raw_bytes: Vec<u8>,
default_input_mode: InputMode,
key_is_kitty_protocol: bool, key_is_kitty_protocol: bool,
) -> Action { ) -> Action {
match *mode { 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) Action::Write(key_with_modifier.cloned(), raw_bytes, key_is_kitty_protocol)
}, },
InputMode::RenameTab => Action::TabNameInput(raw_bytes), InputMode::RenameTab => Action::TabNameInput(raw_bytes),