-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Key representation in bindings #11
Comments
As a side note, it would be nice to have |
I had a deeper look at the code, and IMHO I see two ways forward (well, three...)
I would find option 3 confusing, but the idea would be to:
Perhaps this would allow exposing I would prefer option 2 and I am willing to produce a PR for it. |
The representation of modifiers in the
Key
enum is probably not powerful enough and partially non-coherent.Special characters (it seems non-printable control characters from the unicode control plane) are handled with specific enum branches (
Key::Left
,Key::Home
,Key::Insert
...) while "regular" characters are handled by theKey::Char
branch.The partial inconsistency is due to the fact that it would be possible to create a
Key::Char(c)
where c has the value of the ASCIILEFT
, and it would be different fromKey::Left
but should have the same semantics.This is a bit strange but not bad in practice.
However, it becomes a problem if one wanted to create a
Key
representing the combination of a modifier and a control character.For instance, if I wanted to represent
CTRL-LEFT
I would probably have to create aKey::Ctrl(k)
where k is the "LEFT" ASCII char value, which is not obvious (and I wonder if it would actually work).The "expressive power" problem comes from the impossibility to combine modifiers (there's no way to specify
CTRL-ALT-LEFT
), and from the lack of a "SHIFT" modifier.For instance, "SHIFT-RIGHT" could increase the selection size of one character in a text editor with CUA-like keybindings, but I don't know how to represent this with the
Key
type.Would it be possible to change the
Key
enum to be a struct, logically like this:where
Key
is an enum just like the current one, but without theCtrl
andAlt
branches?This struct, with no special optimization, would be a bit larger than 64 bits, which is unfortunate.
I can imagine several alternative representations that would fit into 64 bits but would make matching less ergonomic.
But before proposing them, is the problem I am describing real, or am I missing something?
How could I handle
CTRL-SHIFT-RIGHT
in the current version ofzi
?I would need it to represent a key binding to "extend the selection by one word" in
zee
:-)The text was updated successfully, but these errors were encountered: