From 2dec26f8ec84fc0141d7e75ecc7d22800c45158e Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Sun, 6 Dec 2026 17:30:47 +0800 Subject: [PATCH 1/2] refactor(tui): simplify undo and redo keybindings Bind undo to Ctrl+_ (plus Kitty-protocol Ctrl+Shift+-), Alt+Z, and Cmd+Z, and bind redo to Alt+Shift+Z and Cmd+Shift+Z. Remove the non-standard Alt+_, Alt+Shift+_, and Alt+Shift+- redo chords, and update keymap tests, app input tests, and the TUI keybindings reference. --- crates/ox-tui/src/app/tests/input.rs | 4 +-- crates/ox-tui/src/input/keymap.rs | 17 +++++------- crates/ox-tui/src/input/keymap/tests.rs | 36 ++++++++++++++++--------- docs/reference/tui/keybindings.md | 24 ++++++++--------- 4 files changed, 44 insertions(+), 37 deletions(-) diff --git a/crates/ox-tui/src/app/tests/input.rs b/crates/ox-tui/src/app/tests/input.rs index fce12c6bf..f35faf195 100644 --- a/crates/ox-tui/src/app/tests/input.rs +++ b/crates/ox-tui/src/app/tests/input.rs @@ -273,14 +273,14 @@ fn undo_and_redo_chords_restore_and_reapply_input_edits() { assert_eq!(app.input(), "hello "); app.handle_key(KeyEvent::new( - KeyCode::Char('_'), + KeyCode::Char('Z'), KeyModifiers::ALT | KeyModifiers::SHIFT, )); assert_eq!(app.input(), "hello world"); app.handle_key(KeyEvent::new(KeyCode::Char('w'), KeyModifiers::CONTROL)); assert_eq!(app.input(), "hello "); - app.handle_key(KeyEvent::new(KeyCode::Char('_'), KeyModifiers::CONTROL)); + app.handle_key(KeyEvent::new(KeyCode::Char('z'), KeyModifiers::ALT)); assert_eq!(app.input(), "hello world"); app.handle_key(KeyEvent::new(KeyCode::Char('z'), KeyModifiers::SUPER)); diff --git a/crates/ox-tui/src/input/keymap.rs b/crates/ox-tui/src/input/keymap.rs index a18694107..a12be3049 100644 --- a/crates/ox-tui/src/input/keymap.rs +++ b/crates/ox-tui/src/input/keymap.rs @@ -713,6 +713,7 @@ fn bind_default_undo_redo(bindings: &mut HashMap) { ), CommandId::Undo, ); + insert_chord(bindings, KeyChord::alt('z'), CommandId::Undo); insert_chord( bindings, KeyChord::new(KeyCode::Char('z'), KeyModifiers::SUPER), @@ -720,21 +721,15 @@ fn bind_default_undo_redo(bindings: &mut HashMap) { ); insert_chord( bindings, - KeyChord::new( - KeyCode::Char('z'), - KeyModifiers::SUPER | KeyModifiers::SHIFT, - ), - CommandId::Redo, - ); - insert_chord(bindings, KeyChord::alt('_'), CommandId::Redo); - insert_chord( - bindings, - KeyChord::new(KeyCode::Char('_'), KeyModifiers::ALT | KeyModifiers::SHIFT), + KeyChord::new(KeyCode::Char('z'), KeyModifiers::ALT | KeyModifiers::SHIFT), CommandId::Redo, ); insert_chord( bindings, - KeyChord::new(KeyCode::Char('-'), KeyModifiers::ALT | KeyModifiers::SHIFT), + KeyChord::new( + KeyCode::Char('z'), + KeyModifiers::SUPER | KeyModifiers::SHIFT, + ), CommandId::Redo, ); } diff --git a/crates/ox-tui/src/input/keymap/tests.rs b/crates/ox-tui/src/input/keymap/tests.rs index 943268e84..c73ed4651 100644 --- a/crates/ox-tui/src/input/keymap/tests.rs +++ b/crates/ox-tui/src/input/keymap/tests.rs @@ -169,10 +169,19 @@ fn default_keymap_maps_undo_redo_history_and_scroll_chords() { ), CommandId::Undo, ), + (KeyChord::alt('z'), CommandId::Undo), ( KeyChord::new(KeyCode::Char('z'), KeyModifiers::SUPER), CommandId::Undo, ), + ( + KeyChord::new(KeyCode::Char('Z'), KeyModifiers::ALT | KeyModifiers::SHIFT), + CommandId::Redo, + ), + ( + KeyChord::new(KeyCode::Char('z'), KeyModifiers::ALT | KeyModifiers::SHIFT), + CommandId::Redo, + ), ( KeyChord::new( KeyCode::Char('Z'), @@ -187,15 +196,6 @@ fn default_keymap_maps_undo_redo_history_and_scroll_chords() { ), CommandId::Redo, ), - (KeyChord::alt('_'), CommandId::Redo), - ( - KeyChord::new(KeyCode::Char('_'), KeyModifiers::ALT | KeyModifiers::SHIFT), - CommandId::Redo, - ), - ( - KeyChord::new(KeyCode::Char('-'), KeyModifiers::ALT | KeyModifiers::SHIFT), - CommandId::Redo, - ), (KeyChord::plain(KeyCode::Up), CommandId::HistoryPrev), (KeyChord::plain(KeyCode::Down), CommandId::HistoryNext), ( @@ -215,6 +215,18 @@ fn default_keymap_maps_undo_redo_history_and_scroll_chords() { "expected {chord:?} -> {command:?}" ); } + + for removed in [ + KeyChord::alt('_'), + KeyChord::new(KeyCode::Char('_'), KeyModifiers::ALT | KeyModifiers::SHIFT), + KeyChord::new(KeyCode::Char('-'), KeyModifiers::ALT | KeyModifiers::SHIFT), + ] { + assert_eq!( + keymap.resolve(&KeyEvent::new(removed.code, removed.modifiers)), + None, + "expected removed chord {removed:?} to be unbound" + ); + } } #[test] @@ -365,11 +377,11 @@ fn chords_for_orders_plain_shift_ctrl_alt_cmd() { ), (CommandId::KillWordRight, &["Ctrl+Delete", "Alt+Delete"]), (CommandId::KillToLineStart, &["Ctrl+U", "Cmd+Backspace"]), - (CommandId::Undo, &["Ctrl+Shift+-", "Ctrl+_", "Cmd+Z"]), ( - CommandId::Redo, - &["Alt+Shift+-", "Alt+Shift+_", "Alt+_", "Shift+Cmd+Z"], + CommandId::Undo, + &["Ctrl+Shift+-", "Ctrl+_", "Alt+Z", "Cmd+Z"], ), + (CommandId::Redo, &["Alt+Shift+Z", "Shift+Cmd+Z"]), (CommandId::HistoryPrev, &["Up", "Ctrl+P"]), (CommandId::HistoryNext, &["Down", "Ctrl+N"]), (CommandId::ScrollUp, &["Shift+Up"]), diff --git a/docs/reference/tui/keybindings.md b/docs/reference/tui/keybindings.md index 519131d63..8b84a77e1 100644 --- a/docs/reference/tui/keybindings.md +++ b/docs/reference/tui/keybindings.md @@ -39,18 +39,18 @@ Default keyboard shortcuts for the interactive TUI, inline overlays, fullscreen ### Editing, Undo, and Clipboard -| Key | Action Name | Description | -| ---------------------------------------------------- | -------------------- | -------------------------------------------------- | -| `Backspace` | `backspace` | Delete character before the cursor | -| `Delete` | `delete` | Delete character at the cursor | -| `Ctrl+Backspace`, `Ctrl+W`, `Alt+Backspace` | `kill-word-left` | Kill the word before the cursor | -| `Ctrl+Delete`, `Alt+Delete` | `kill-word-right` | Kill the word after the cursor | -| `Ctrl+U`, `Cmd+Backspace` | `kill-to-line-start` | Kill text to the start of the current line | -| `Ctrl+K` | `kill-to-line-end` | Kill text to the end of the current line | -| `Ctrl+Y` | `yank` | Yank the most recently killed text at the cursor | -| `Ctrl+_`, `Ctrl+Shift+-`, `Cmd+Z` | `undo` | Undo last input edit | -| `Cmd+Shift+Z`, `Alt+_`, `Alt+Shift+_`, `Alt+Shift+-` | `redo` | Redo last undone input edit | -| `Ctrl+V`, `Alt+V` | `paste-clipboard` | Paste an image or text from the local OS clipboard | +| Key | Action Name | Description | +| ------------------------------------------- | -------------------- | -------------------------------------------------- | +| `Backspace` | `backspace` | Delete character before the cursor | +| `Delete` | `delete` | Delete character at the cursor | +| `Ctrl+Backspace`, `Ctrl+W`, `Alt+Backspace` | `kill-word-left` | Kill the word before the cursor | +| `Ctrl+Delete`, `Alt+Delete` | `kill-word-right` | Kill the word after the cursor | +| `Ctrl+U`, `Cmd+Backspace` | `kill-to-line-start` | Kill text to the start of the current line | +| `Ctrl+K` | `kill-to-line-end` | Kill text to the end of the current line | +| `Ctrl+Y` | `yank` | Yank the most recently killed text at the cursor | +| `Ctrl+_`, `Ctrl+Shift+-`, `Alt+Z`, `Cmd+Z` | `undo` | Undo last input edit | +| `Alt+Shift+Z`, `Cmd+Shift+Z` | `redo` | Redo last undone input edit | +| `Ctrl+V`, `Alt+V` | `paste-clipboard` | Paste an image or text from the local OS clipboard | ### History and Submission From 99b27433c40a309c05fa9bb327e6c542f0d15471 Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Sun, 6 Dec 2026 17:42:46 +0800 Subject: [PATCH 2/2] test(tui): drop redundant negative assertions for removed redo chords --- crates/ox-tui/src/input/keymap/tests.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/crates/ox-tui/src/input/keymap/tests.rs b/crates/ox-tui/src/input/keymap/tests.rs index c73ed4651..8645177a9 100644 --- a/crates/ox-tui/src/input/keymap/tests.rs +++ b/crates/ox-tui/src/input/keymap/tests.rs @@ -215,18 +215,6 @@ fn default_keymap_maps_undo_redo_history_and_scroll_chords() { "expected {chord:?} -> {command:?}" ); } - - for removed in [ - KeyChord::alt('_'), - KeyChord::new(KeyCode::Char('_'), KeyModifiers::ALT | KeyModifiers::SHIFT), - KeyChord::new(KeyCode::Char('-'), KeyModifiers::ALT | KeyModifiers::SHIFT), - ] { - assert_eq!( - keymap.resolve(&KeyEvent::new(removed.code, removed.modifiers)), - None, - "expected removed chord {removed:?} to be unbound" - ); - } } #[test]