feat(core): add ctrl+n/ctrl+p keybindings for navigation#559
Open
rafa-thayto wants to merge 1 commit into
Open
feat(core): add ctrl+n/ctrl+p keybindings for navigation#559rafa-thayto wants to merge 1 commit into
rafa-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 |
Author
|
I was implementing this on my CLI, but I thought it would probably be a better idea to implement it directly here! |
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.
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).