Repository navigation
fix(tui): ignore letter shortcuts when ctrl or alt is held - #669
Open
eric-engberg wants to merge 3 commits into
Open
eric-engberg wants to merge 3 commits into
eric-engberg wants to merge 3 commits into
Conversation
Letter shortcuts compared the typed character without checking modifiers, so ctrl+letter and alt+letter ran the plain-letter action: ctrl+r toggled raw value, ctrl+d deleted a widget, and on macOS alt+arrow (sent as ESC + letter) fired whatever letter followed. A few handlers patched ctrl+s one key at a time with `&& !key.ctrl`; widget keybinds checked ctrl but not alt. Shortcuts now compare against getPlainInput(), which is empty while ctrl or alt/option is held, across the line editor, widget keybinds, Edit Colors, Global Overrides, Powerline setup/themes/separators, the line selector and the hide-state checklist. Arrows, Enter, ESC, shift and text entry are unchanged, and modifier combos are free for bindings of their own.
The shortcut tests sent keys and checked the result after a fixed 25 ms. On a busy machine Ink can take longer, so the bare-key cases could fail even though the shortcut works. They now wait until the shortcut's effect shows (up to 3 s), and a follow-up key waits for the previous key's redraw. Checks that a modified key does nothing give it 150 ms to act. After each wait the test also gives React two setImmediate turns: React draws a frame, then attaches the new input listener in a scheduled effect, so a key sent the moment the frame shows could reach no listener.
# Conflicts: # src/tui/components/items-editor/input-handlers.ts
eric-engberg
force-pushed
the
fix/hotkey-modifiers
branch
from
October 7, 2026 01:23
53570ee to
dd3dbdf
Compare
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.
Problem
Letter shortcuts compared the typed character without checking modifiers, so a ctrl or alt combo ran the plain-letter action:
ESC b/ESC f, which Ink reads as alt+b / alt+f. Word-jumping with option-arrow could therefore toggle bold, background mode, and so on.&& !key.ctrl. Widget keybinds checked ctrl but not alt.Fix
getPlainInput(input, key)inutils/input-guards.tsreturns the typed character only for a bare keypress, and''while ctrl or alt/option is held. Every letter shortcut now compares against it:These are unchanged:
A/ahandlers keep workingshouldInsertInputThe ad-hoc
!key.ctrlpatches are gone, and modifier combos are free for bindings of their own.Modifiers on macOS and Windows/Linux
Ink 6.2 reports
ctrl,meta(alt/option) andshift:ctrlandmetacovers Ctrl, PC Alt, and Mac Option when "Option as Meta/Esc+" is on.∫,®, …), which never matches a shortcut letter.Testing
getPlainInputunit tests.a i d k c r mdo nothing, the bare letter still works, and widget keybinds ignore alt as well as ctrl.hotkey-modifiers.test.ts: a table-driven Ink test that sends the real terminal bytes. Ctrl is the control character, e.g.\x12for ctrl+r; alt isESC+ key. For one shortcut in each of the seven components, it checks that the bare key fires and ctrl and alt don't. ctrl+i isn't used because it's the same byte as Tab.main(with docs: explain an empty status line in one folder (workspace trust) #606 and feat(git-is-fork): render forks as an editable glyph #617 merged in locally):bun testgives 2809 pass, 0 fail (Bun 1.4.2), andbun run lintis clean. Under Node 26 vitest, the 3 touched test files pass (70).mainin plain and Powerline modes, and the TUI opens and exits under both.M-andC-sequences: alt+b, ctrl+r and alt+d do nothing in the line editor, while plainbandrwork.