feat(useKeybinds): add useKeybinds #4756
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before submitting the PR, please make sure you do the following
fixes #123
).Description
The name is quite self-explanatory, so I will give an example use case. Also I've checked all existing key related functions, but I don't think any of them solves the following situation well.
Let's say I have a issue tracking app and I want to have keybinds for some actions like
Ctrl + k
to open command palette,s - d
(key sequence) to change issue state to done, etc.Also in VueUse docs, vitepress has
Ctrl/Command + k
for search. Something like that is really easy to implement withuseKeybinds
.Additional context
This feature is inspired by Nuxt UI - defineShortcuts. However their implementation lacks a few key pieces like using modifier keys in sequence.
Instead of updating their implementation I decided to make this function, so anybody can benefit, including Nuxt UI (if they want) since they use this lib already.
For reviewers
Interface, probably the most important part as it is a new function. Would be nice to make sense to others, not just me (even though I think it's quite standard).
Also I have
internal.ts
file with tests, because I wanted to test more than the "public interface" and I don't need every function to be exported from lib.I didn't see this approach anywhere else, so let me know if there are conventions about that. I didn't find it.