zee-editor/zee

Configurable key bindings

massimiliano-mantione opened this issue · 2 comments

First of all, thanks for your work on zee!

I am exploring, looking for a "simple" editor to use in the terminal when I am not using my regular "IDE" editor, and zee, among the ones I tried, is the one that is actually able to work on huge files without becoming unresponsive :-)
(I want a "simple" editor but I want to be able to use it without fear on any file I stumble upon)
So, thanks for that!

That said, while I understand your focus on "emacs-compatible experience", I am unwilling to abandon the keybindings I am used to, or to be forced to use different keybindings with different editors.

I had a look at the source code and I see no way to load keybindings from a file.
I see there is a toml file that is looked up at startup but AFAICS it only provides an index into a theme.

About keybindings, AFAICS they are hardcoded in the various Component::bindings implementations.

Assuming that I did not make gross mistakes reading the code, would you accept a PR that:

  • implements a way to deserialize KeyPattern instances from strings
  • using that, implements a way to load "keybinding mappings" from the config file, falling back to the hardcoded defaults
  • passes this "mapping table" to the various Component::bindings implementations so that bindings will not be hard-coded anymore (they would be created from the loaded mapping table)

The "keybinding mappings table" would be a dictionary with commands ('static &str) as keys, where each command is one of "left", "start-of-line"...
For each command, there would be a Message, and a SmallVec of KeyPattern (the key patterns that would trigger the command).
This would make it possible to implement all the Component::bindings functions taking the mappings they need from the table instead of using hardcoded values like they do now.

I imagine that the performance impact of creating the bindings this way would be negligible.

Does this make sense?
If it does, and if you would accept this feature, I might write the PR in the next weeks (slowly, as I have a full-time job and a family).

Thank you for trying zee and for the detailed issue description, very helpful and nice to see this is already useful for someone 🙂 Editing very large files with breeze is certainly a main goal of zee and one of the reasons I started it.

Configurable key bindings, not to mention extensibility more generally, are very important and at the top of the roadmap. I added the Component::bindings abstraction recently to address a few things, one of which is configurable key bindings. Defining the bindings in code is just a stop gap solution.

@massimiliano-mantione while at it, would you also consider modal key bindings support?