Skip to content
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

feat(yazi): Add assertion to prevent conflicting keybinds #6343

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lordkekz
Copy link
Contributor

@lordkekz lordkekz commented Jan 20, 2025

Description

Right now, you can accidentally define conflicting keybinds and you will not get any warning.
This PR adds an assertion which checks if there are any two keybinds A and B where the on value (sequence of keypresses) of A starts with the on value of B.

This is not yet finished but I will pick it up when I have time again.

The new assertions produce error messages like this:

There are conflicting keybinds in: `programs.yazi.keymap.input`
┢ Conflict between:
┃ {"on":["<Esc>"],"run":"escape"}
┃ {"on":["<Esc>"],"run":"backspace"}


--
There are conflicting keybinds in: `programs.yazi.keymap.manager`
┢ Conflict between:
┃ {"on":["c","d","e"],"run":"something"}
┃ {"on":["c","d"],"run":"somethingelse"}
│
┢ Conflict between:
┃ {"on":["q"],"run":"escape"}
┃ {"on":["q"],"run":"quit"}

Caveats

  • For now, it only checks for conflicts of keybinds which are defined in the home-manager config. It does not check for conflicts with yazi's default keymap.
    • The latter is theoretically possible e.g. by parsing the default keymap.toml (would require IFD) or by maintining a Nix-language version of it.
    • If checks with default bindings get added, it would be important to indicate them as such (and ignore overriding the defaults).
  • I would be nice to be able to print the definition location of each keybind, i.e. the home-manager module that added it to the list, but I'm not sure how to do that easily.

Checklist

  • Change is backwards compatible.

  • Code formatted with ./format.

  • Code tested through nix-shell --pure tests -A run.all or nix develop --ignore-environment .#all using Flakes.

  • Test cases updated/added. See example.

Maintainer CC

@XYenon @eljamm
btw would you be interested in me becoming a maintainer of the yazi module?
This is my second contribution to this module and I am also maintaining the nix-yazi-plugins repo (not afiliated with yazi or home-manager but relevant IMO), so I plan to keep contributing here in the forseeable future.

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.

1 participant