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

Custom keybindings #38

Merged
merged 2 commits into from
Aug 29, 2022

Conversation

CosmicHorrorDev
Copy link
Collaborator

Resolves #34

This implements things as listed in #34 with a couple of small tweaks due to issues in winit

  • The amount of usable keys is slimmed down
  • Shift now has to be specified regardless of the key (I originally wanted "G" to represent Shift+g, but the platform inconsistencies with how things like + are expressed (Shift+= vs Shift++) made me walk this back)

There is now a new section in the config file for keybindings. Here's the one from `inlyne.toml.sample

[keybindings]
# Base will override the defaults if set
# Default: Not set
base = [
    ["ToTop", "Home"],
    ["ToBottom", "End"],
    ["Copy", { key = "c", mod = ["Ctrl"] }],
    ["ToTop", ["g", "g"]],
    ["ToBottom", { key = "g", mod = ["Shift"] }],
    ["Copy", "y"],
]
# Extra will be applied on top of base/defaults
extra = ... # Refer to `base`

A decent amount of the code goes into deserializing this. I wanted to allow for the config to be simple, so you can see that you can do things like provide a single key instead of a full combo, or provide just the key if there are no modifiers

The other bulk of the changes is for handling KeyCombos. It's a struct that gets initialized with the keybindings. Afterwards it can consume keys and will emit if they corresponded to some action


Here's everything in action. The section of my config for reference

[keybindings]
extra = [
    ["Copy", "y"],
    ["ScrollUp", "k"],
    ["ScrollDown", "j"],
    ["ToTop", ["g", "g"]],
    ["ToBottom", { key = "g", mod = ["Shift"] }],
    ["Quit", "q"],
    ["Quit", [{ key = "z", mod = ["Shift"] }, { key = "z", mod = ["Shift"] }]],
    ["Quit", [{ key = "z", mod = ["Shift"] }, { key = "q", mod = ["Shift"] }]],
]
keybindings_demo.mp4

@trimental
Copy link
Collaborator

Looks brilliant can't wait to try this out when I review it tonight

@trimental
Copy link
Collaborator

I tried it and I love it. The vim style shortcuts feel really good and honestly I might be tempted to implement a ghetto version of 10j, 3k..etc in the future just to move around faster in vim style. Looking at the code its clear to see how well thought out this was, so I think this is good to merge the way it is.

With this, checklist support, customising line scrolling and live reloading, I'll make another weekly release of v0.2. Unless any other spectacular changes come along I think I'll change to bi-weekly releases after this one for stability. 🥳

@trimental trimental merged commit 10a27ab into Inlyne-Project:main Aug 29, 2022
@CosmicHorrorDev
Copy link
Collaborator Author

Some sort of vim-mode shouldn't be too hard to hack into the current system since it would just involve:

  • Erroring on commands that start with numbers
  • Special-casing if we get some numbers before a command
  • Adding vim-like keybindings to the default keybindings

@trimental
Copy link
Collaborator

Maybe you could match the number for any current bindings and if there isn't any then you store the number for the next time that you press j or k. That way you could still accept bindings starting with numbers, as I think a user would understand if they bind 5 to an action they can't expect 5j to work. About the vim-like bindings been set as default I think a lot of users would like that.

@CosmicHorrorDev CosmicHorrorDev deleted the custom-keybindings branch April 6, 2024 04:13
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.

Custom Keybinds
2 participants