From b3ed356c1be03b5e3ebb1dc4f6f4dc663247804b Mon Sep 17 00:00:00 2001 From: Manuel Wettstein Date: Tue, 20 May 2025 11:11:48 +0200 Subject: [PATCH] Untangles the keystrokes ctrl-h and backspace Before this commit, pressing either `ctrl-h` or `backspace` both generated the same `Key::Backspace`, even though they send the distinct bytes `8` and `127` to tiny. Now, they generate distinguishable events. Also added a new default configuration for `Key::Ctrl('h')` so that the default behavior of tiny remains precisely the same as before, but with additional configurability of `ctrl_h` that is separate from `backspace`. --- crates/libtiny_tui/src/key_map.rs | 1 + crates/term_input/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/libtiny_tui/src/key_map.rs b/crates/libtiny_tui/src/key_map.rs index 02ba4bcb..5516e15e 100644 --- a/crates/libtiny_tui/src/key_map.rs +++ b/crates/libtiny_tui/src/key_map.rs @@ -82,6 +82,7 @@ impl Default for KeyMap { (Key::Arrow(Arrow::Down), KeyAction::InputNextEntry), (Key::Char('\r'), KeyAction::InputSend), (Key::Backspace, KeyAction::InputDeletePrevChar), + (Key::Ctrl('h'), KeyAction::InputDeletePrevChar), (Key::Del, KeyAction::InputDeleteNextChar), (Key::Ctrl('a'), KeyAction::InputMoveCursStart), (Key::Ctrl('e'), KeyAction::InputMoveCursEnd), diff --git a/crates/term_input/src/lib.rs b/crates/term_input/src/lib.rs index 03fa46fd..9fbecb42 100644 --- a/crates/term_input/src/lib.rs +++ b/crates/term_input/src/lib.rs @@ -178,7 +178,6 @@ byte_seq_parser! { [27, 91, 50, 51, 126] => Key::FKey(FKey::F11), [27, 91, 50, 52, 126] => Key::FKey(FKey::F12), [9] => Key::Tab, - [8] => Key::Backspace, [127] => Key::Backspace, [1] => Key::Ctrl('a'), [2] => Key::Ctrl('b'), @@ -187,6 +186,7 @@ byte_seq_parser! { [5] => Key::Ctrl('e'), [6] => Key::Ctrl('f'), [7] => Key::Ctrl('g'), + [8] => Key::Ctrl('h'), [10] => Key::Ctrl('j'), [11] => Key::Ctrl('k'), [12] => Key::Ctrl('l'),