From 8bd555c310cb3352aaaac7860715fb5a5e6e33a0 Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Fri, 8 Nov 2024 11:26:09 +0100 Subject: [PATCH] fix(input): refix ctrl-j --- zellij-utils/src/input/keybinds.rs | 31 +++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/zellij-utils/src/input/keybinds.rs b/zellij-utils/src/input/keybinds.rs index 99ec0992b..3da34e4b8 100644 --- a/zellij-utils/src/input/keybinds.rs +++ b/zellij-utils/src/input/keybinds.rs @@ -1,7 +1,7 @@ use std::collections::{BTreeMap, HashMap}; use super::actions::Action; -use crate::data::{InputMode, KeyWithModifier, KeybindsVec}; +use crate::data::{BareKey, InputMode, KeyWithModifier, KeybindsVec}; use serde::{Deserialize, Serialize}; use std::fmt; @@ -44,8 +44,13 @@ impl Keybinds { ) -> Vec { self.0 .get(mode) - .and_then(|normal_mode_keybindings| normal_mode_keybindings.get(key_with_modifier)) - .cloned() + .and_then(|mode_keybindings| { + if raw_bytes == &[10] { + handle_ctrl_j(&mode_keybindings, &raw_bytes, key_is_kitty_protocol) + } else { + mode_keybindings.get(key_with_modifier).cloned() + } + }) .unwrap_or_else(|| { vec![self.default_action_for_mode( mode, @@ -107,6 +112,26 @@ impl Keybinds { } } +// we need to do this because [10] in standard STDIN, [10] is both Enter (without a carriage +// return) and ctrl-j - so here, if ctrl-j is bound we return its bound action, and otherwise we +// just write the raw bytes to the terminal and let whichever program is there decide what they are +fn handle_ctrl_j( + mode_keybindings: &HashMap>, + raw_bytes: &[u8], + key_is_kitty_protocol: bool, +) -> Option> { + let ctrl_j = KeyWithModifier::new(BareKey::Char('j')).with_ctrl_modifier(); + if mode_keybindings.get(&ctrl_j).is_some() { + mode_keybindings.get(&ctrl_j).cloned() + } else { + Some(vec![Action::Write( + Some(ctrl_j), + raw_bytes.to_vec().clone(), + key_is_kitty_protocol, + )]) + } +} + // The unit test location. #[cfg(test)] #[path = "./unit/keybinds_test.rs"]