feat(core): add ctrl+n/ctrl+p keybindings for navigation#559
feat(core): add ctrl+n/ctrl+p keybindings for navigation#559rafa-thayto wants to merge 1 commit into
Conversation
Add emacs-style ctrl+n (down) and ctrl+p (up) as default aliases,
matching the existing vim j/k aliases. Control chords arrive as raw
bytes ('\x0e'/'\x10'), so the cursor-alias lookup in Prompt.onKeypress
now checks char and key.sequence alongside key.name, mirroring how the
'\x03' cancel alias is matched.
Cursor-driven prompts (select, multi-select, group-multiselect, date,
confirm) pick the aliases up through the existing cursor-event system.
Autocomplete and multi-line resolve control chords explicitly via the
new getActionForControlKey helper, guarded on key.ctrl so typed letters
(like the j/k aliases) never hijack text input. In multi-line this also
stops the raw control bytes from being inserted into the text.
🦋 Changeset detectedLatest commit: 90c2c27 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
I was implementing this on my CLI, but I thought it would probably be a better idea to implement it directly here! |
commit: |
dreyfus92
left a comment
There was a problem hiding this comment.
hey @rafa-thayto, thanks for putting this together, the write-up is super clear and clean. but i don't think we're going to merge this one. clack already ships arrow keys + vim(hjkl) for navigation, and we'd rather keep the default keymap lean than grow a third set of bindings into core. it's less about this change specifically and more about where we draw the line on what's built in by default.
we're also starting to ask folks to open an issue before a pr so we align on direction first, no worries on this one since that wasn't in place yet.
we really appreciate you taking a swing at this 😄
Summary
Adds emacs-style
ctrl+n/ctrl+pkeybindings as default aliases fordown/upnavigation, alongside the existing vimj/kaliases.settings.ts— registers'\x10'→up(ctrl+p) and'\x0e'→down(ctrl+n) in the default alias table under an// emacs supportblock; adds agetActionForControlKey(char, key)helper (sibling ofisActionKey) that resolves control chords, guarded onkey.ctrlso typed letters can never alias navigation in text inputs.prompt.ts— the cursor-alias lookup inonKeypressnow checks[char, key.name, key.sequence]instead ofkey.nameonly, mirroring how the pre-existing'\x03'(ctrl+c) cancel alias is matched. Control chords reportkey.nameas the bare letter ('n'), so the raw sequence is the only safe key to match on.autocomplete.ts—ctrl+n/ctrl+pnavigate the option list (the prompt tracks text input, so it readskey.name === 'up'/'down'directly and needed explicit chord resolution).multi-line.ts—ctrl+n/ctrl+pmove the cursor between lines; previously the raw\x0e/\x10bytes were inserted into the user's text.Every cursor-driven prompt (
select,multi-select,group-multiselect,date,confirm) picks the aliases up automatically through the existing cursor-event system, andupdateSettings({ aliases })keeps working unchanged for user-defined sequences.Test plan
n/p), autocomplete list navigation, multi-line cursor movement without text mutation.selectresponds to ctrl+n/ctrl+p.biome checkandtsc --noEmitclean.@clack/coreminor).