You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: add initial support for multi-stroke chord keybindings in emacs mode - #989
(Breaking change) Remove the existing pub field of Keybindings so we can unify the implementation between single-keystroke bindings and multi-keystroke bindings.
I did some searching on GitHub and couldn't immediately find specific cases that would be broken by this -- but of course, that doesn't prove it won't break a client. (Most of the search hits that came up seemed to be vendored/forked copies of reedline or nushell, or similar field names in different types.)
Adds Keybindings::add_sequence_binding() and Keybindings::remove_sequence_binding() to bind (or unbind) a sequence of 1 or more KeyCombinations to a ReedlineEvent; this supports both single-keystroke bindings and multi-keystroke chord-style bindings.
Retains Keybinding::add_binding() and Keybinding::remove_binding() for backwards compatibility, replacing their bodies with simple wrapping calls to the new sequence-enlightened calls.
General approach:
Do not allow a registered keystroke to be a strict prefix of another registered keystroke.
Support arbitrarily long chords.
Use a trie to store key bindings for efficient matching.
Unify handling of single-keystroke keybindings with multiple-keystroke keybindings (do not special-case one vs. the other).
Focus on emacs mode first; do not worry about aligning with existing multi-keystroke processing already present in vi mode for handling commands.
I'm looking for feedback on the general approach as well as the implementation before getting any deeper into this. For reference, I've demonstrated how this support could be used in nushell via this commit in my nushell fork. There's also a new example included in this draft PR to demonstrate and test.
(Aside: This is my first feature-level contribution. I'm eager to get as much feedback as I can!)
Thanks for taking the time to put this up. I added a comment to your nushell commit above. I think the code seems plausible but I'm not a big fan of the configuration aspect of it.
Nice foundation.
Heads up that @benvansleen's #1016 is solving the same chord problem from the other end and I think the trie you put in Keybindings is the cleaner base of the two, so it'd be great to join forces.
A couple of things #1016 already handles that this is missing:
a timeout flush (needed for jj-in-insert, where a lone j has to self-insert after a pause), and the case where a key is both a binding and a prefix (j→Down and jj→Esc, which the trie currently disallows).
Could the two be combined... your trie as storage, his resolver + timeout on top as one shared piece the modes embed?
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
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.
Adds basic support for adding multi-stroke (chord) keybindings, e.g.:
Changes to public API:
(Breaking change) Remove the existing
pubfield ofKeybindingsso we can unify the implementation between single-keystroke bindings and multi-keystroke bindings.I did some searching on GitHub and couldn't immediately find specific cases that would be broken by this -- but of course, that doesn't prove it won't break a client. (Most of the search hits that came up seemed to be vendored/forked copies of
reedlineornushell, or similar field names in different types.)Adds
Keybindings::add_sequence_binding()andKeybindings::remove_sequence_binding()to bind (or unbind) a sequence of 1 or moreKeyCombinations to aReedlineEvent; this supports both single-keystroke bindings and multi-keystroke chord-style bindings.Retains
Keybinding::add_binding()andKeybinding::remove_binding()for backwards compatibility, replacing their bodies with simple wrapping calls to the new sequence-enlightened calls.General approach:
emacsmode first; do not worry about aligning with existing multi-keystroke processing already present in vi mode for handling commands.I'm looking for feedback on the general approach as well as the implementation before getting any deeper into this. For reference, I've demonstrated how this support could be used in
nushellvia this commit in mynushellfork. There's also a new example included in this draft PR to demonstrate and test.(Aside: This is my first feature-level contribution. I'm eager to get as much feedback as I can!)