Skip to content

Conversation

@reubeno
Copy link
Contributor

@reubeno reubeno commented Dec 23, 2025

Adds basic support for adding multi-stroke (chord) keybindings, e.g.:

// Add chord bindings
// Ctrl+X Ctrl+C: Quit
keybindings.add_sequence_binding(
    &[ctrl('x'), ctrl('c')],
    ReedlineEvent::CtrlD,
);

Changes to public API:

  • (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!)

@fdncred
Copy link
Contributor

fdncred commented Dec 23, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants