feat: add configurable keyboard shortcuts (#211) - #226
Merged
Conversation
Add an optional `[shortcuts]` table to `config.toml` that remaps the 15 action/navigation keys (copy, clear, save, record, search_toggle, toggle_case, toggle_regex, page_up/down, jump_start/end, word_left/right, next/prev_bookmark), merged over the built-in per-platform defaults. A new `inputs/keymap.rs` (Action / KeyBinding / Keymap) owns all key knowledge: config modifier names are logical and resolved once to the physical crossterm event of the build target (macOS Ctrl+arrow -> Alt, Windows jump defaults on Ctrl), and matching is exact. `handle_key_input` resolves a remappable action before the intrinsic key match, with the Tab-bound next_bookmark yielding to `@tag` autocomplete. Text-editing and control keys stay fixed and are rejected as override targets. Unknown actions, bad key strings, reserved keys and duplicate bindings are fatal config errors. An unbound Ctrl/Alt+letter is now swallowed instead of typed (AltGr, i.e. Ctrl+Alt together, still types). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Closes #211. Adds an optional
[shortcuts]table toconfig.tomlthat lets users remap the action/navigation keyboard shortcuts, merged over the built-in per-platform defaults (an omitted action keeps its default).15 remappable actions:
copy,clear,save,record,search_toggle,toggle_case,toggle_regex,page_up,page_down,jump_start,jump_end,word_left,word_right,next_bookmark,prev_bookmark. Text-editing/control keys (typing, Enter, Esc, arrows, Home/End, Backspace/Delete, headlessCtrl+K/Ctrl+Q) stay fixed.How
src/inputs/keymap.rs(new) —Action/KeyBinding/Keymapown all key knowledge;config.rsstays a plainBTreeMap<String,String>and never enumerates the action set."Ctrl+Left","Shift+Tab","F2") are parsed once into the physical crossterm event of the build target, so a config file is portable: the macOSCtrl+arrow → Alt+arrowterminal quirk is handled inresolve, and the Windowsjump_*defaults areCtrl+PageUp/Down(vsAltelsewhere). Matching is exact on modifiers, case-insensitive on chars. Adefault_matches_current_armstest proves the default keymap reproduces the old hardcoded arms per platform.handle_key_inputresolves a remappable action before the intrinsic key match; aTab-boundnext_bookmarkfalls through to@tagautocomplete while the pop-up is up. The oldCTRL_MODIFIER/ACTION_MODIFIERconsts are gone (onlyACTION_MODIFIER, for the fixedAlt+Enterarm, remains).main's existing[ERR]funnel.Behavior change
An unbound
Ctrl/Alt+letter is now swallowed rather than typed literally (e.g.Ctrl+Caftercopyis remapped away).AltGr(Ctrl+Alttogether, the Windows international-layout signature) still types.Tests
keymap.rsunit tests: parser round-trips & rejections, per-platformresolve, exact/case-fold matcher, merge/swap, unknown/reserved/duplicate errors, and the anti-regression default-parity table.config.rs:[shortcuts]parsing.inputs_task.rs: thechar_is_literal_texttyping/AltGr predicate.tests/tui_e2e.rs: a config-driven remap (record → Ctrl+G, proving override + old-key disabled) and a headlessCtrl+F-swallow test. The e2e harness now isolates the config dir to a temp tree.All 226 unit + 14 e2e tests pass (1 e2e ignored on macOS per the existing PTY-baud limitation); tree is warning-clean under
#![deny(warnings)]. Docs updated (README shortcut table gains a "Config action" column + a "Custom shortcuts" section; CLAUDE.md).🤖 Generated with Claude Code