fix(input): refix ctrl-j (#3746)

* fix(input): refix ctrl-j

* fix e2e tests
This commit is contained in:
Aram Drevekenin 2024-11-08 14:34:47 +01:00 committed by GitHub
parent d22204692a
commit e8b95402d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 4 deletions

View file

@ -20,7 +20,7 @@ use super::remote_runner::{RemoteRunner, RemoteTerminal, Step};
pub const QUIT: [u8; 1] = [17]; // ctrl-q pub const QUIT: [u8; 1] = [17]; // ctrl-q
pub const ESC: [u8; 1] = [27]; pub const ESC: [u8; 1] = [27];
pub const ENTER: [u8; 1] = [10]; // char '\n' pub const ENTER: [u8; 2] = [10, 13]; // '\n\r'
pub const SPACE: [u8; 1] = [32]; pub const SPACE: [u8; 1] = [32];
pub const LOCK_MODE: [u8; 1] = [7]; // ctrl-g pub const LOCK_MODE: [u8; 1] = [7]; // ctrl-g

View file

@ -1,7 +1,7 @@
use std::collections::{BTreeMap, HashMap}; use std::collections::{BTreeMap, HashMap};
use super::actions::Action; use super::actions::Action;
use crate::data::{InputMode, KeyWithModifier, KeybindsVec}; use crate::data::{BareKey, InputMode, KeyWithModifier, KeybindsVec};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fmt; use std::fmt;
@ -44,8 +44,13 @@ impl Keybinds {
) -> Vec<Action> { ) -> Vec<Action> {
self.0 self.0
.get(mode) .get(mode)
.and_then(|normal_mode_keybindings| normal_mode_keybindings.get(key_with_modifier)) .and_then(|mode_keybindings| {
.cloned() 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(|| { .unwrap_or_else(|| {
vec![self.default_action_for_mode( vec![self.default_action_for_mode(
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<KeyWithModifier, Vec<Action>>,
raw_bytes: &[u8],
key_is_kitty_protocol: bool,
) -> Option<Vec<Action>> {
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. // The unit test location.
#[cfg(test)] #[cfg(test)]
#[path = "./unit/keybinds_test.rs"] #[path = "./unit/keybinds_test.rs"]