-
Notifications
You must be signed in to change notification settings - Fork 19
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
How to use vscode-which-key to execute an existing keybinding? #5
Comments
As an aside, the above 3 conditions is how I expect |
Sorry for the various edits to the original description, had to clarify exactly what my keybindings do 🙂 |
I would like to have this as well. I don't know if there's a way to execute keybinding from an extension. AFAIK, there is currently no easy way for an extension to read the condition in |
As far as the ability to execute arbitrary keybindings from an extension, I'm going to try looking for examples or issues in the vscode repo to see if this has already been discussed before at some point, and open one and link it here if I can't find anything concrete. I'd really like it if this could be added; for context, I have a keymap called "Chord Heavy" in the marketplace that has a lot of chords set up in a Spacemacs-esque fashion that I'd like to port over to VSpace code if possible, which is why I'm showing a ton of interest in this project in particular 😅 |
Having One hacky way to get around is to use Thank you for interested in this. We would love to have a community to make this better for most people and have to best out-of-box experience for people like spacemacs. Free feel to open issues to track any missing work, feature requests, just asking questions. This repo is focused on the core code behind the menu display structure which can be a stand alone extension and as well for other extension to consume (like how VSpaceCode bundles this), and ships with a default bindings that doesn't using any third party extension. The VSpaceCode repo, it hosts the best-of-the box experience like spacemacs with different bindings that uses third party extensions. |
There are two options I am thinking. One is something you can do today, the another one involved more thinking and infrastructure. First option: {
// Adding this will allow VSpaceCode to run when side bar is focused
{
"key": "space",
"command": "vspacecode.space",
"when": "sideBarFocus && !inputFocus && !whichkeyActive"
},
// This is the workaround part, where it will intercept `t` when `whichkeyActive && sideBarVisible && explorerViewletVisible` and pass it back to `which key` as `t_` input.
{
"key": "t",
"command": "whichkey.triggerKey",
"args": "t_",
"when": "whichkeyActive && sideBarVisible && explorerViewletVisible"
}
} Merge the following settings to your {
"vspacecode.bindingOverrides": [
// This adds an entry to <spc> f with a key `t_` which will be triggered by the interpretation mechanism.
{
"keys": "f.t_",
"name": "Hide side bar",
"type": "command",
"command": "workbench.action.toggleSidebarVisibility"
},
],
} Explanation:
This workaround works today with no in infrastructure change, although, there are some changes I can see to make this workaround a little bit better.
One downside of this approach is that, Second option involves more infrastructure change. The process is similar, instead of passing just the key in the interception, pass an extra parameter like named {
"key": "t",
"name": "Show tree/explorer view",
"type": "conditional",
"commands": ["workbench.view.explorer", "workbench.action.toggleSidebarVisibility"],
"conditional": [null, "sideBarVisible && explorerViewletVisible"]
} Ideally, I think I will work toward something like the second option, but first option is something you can do today :) Sorry for such a long comment. I am just dumping my current thoughts so I don't forget about them. |
I appreciate the thorough response, so please don't worry about lengthy comments, I welcome them. As for your workaround, I like it but for one.... it feels a bit hacky. I feel like I'd make it and then a week from now come back and completely forget how I actually created it. And of course, with no sane "go to definition" functionality for keybindings or settings JSON documents, I'd be stuck trying to remember exactly how this works, and I'm not a fan of configurations that can feel a bit too magical. I'm patient enough to wait for a "proper" implementation, at least on the consumer side (I'd hate it for this to get a bit hacky on your side, but naturally I'd leave that decision up to you). Unfortunately, your first option in the latest comment won't work, because it doesn't keep all three conditions under the same keybinding. As far as I can tell, it only will close the sidebar if the explorer view is visible, which only matches 1/3 of the options that To be honest, the current implementation of Last thing; I do think that your exploration into how to implement "when" conditions similar to how you can set them in native keybindings is worth continuing, but not sure if it fits into the spirit of this issue. Perhaps you should create a new issue referencing that to make sure that you don't lose that train of thought? |
Just want to make sure I understand. The first option doesn't work for you because
and
If there is a functionally issue, I'd like to know what's missing. I am current running that config and it seems to satisfy your 3 conditions you mentioned in the first post.
I read this issue more as how to execute binding with a |
Yeah honestly I opened this in the spirit of "can this extension run existing shortcuts directly", so a new issue might be better. As for implementation, I must've messed something up, because I just double-checked my config and its working as expected; sorry about that. I don't think I want to keep it that way more because of the configuration issue though. |
Created #11, although, realistically I am not optimistic that vscode will ever allow extension to invoke keybindings (shortcuts). |
@stevenguh just noticed an unintentional side effect of the above Now when I execute Also, I replaced the default |
That's the one of the cons about that approach (hack) I described above.
You can add |
Oh blah sorry I glossed over that bit. Thanks! |
As an example, I have the following in my
keybindings.json
already:The gist of the above keybindings is that it does one of three things when the chord
cmd+f t
is invoked:It works just fine. I'm trying to set up a which-key binding via VSpaceCode, however I can't figure out how to get this extension to execute a keyboard shortcut, and not a specific command. Right now I can't figure out how to get the above functionality baked into VSpaceCode (via which-key) so I'd rather just be able to execute a keybinding directly instead.
Is it possible to tell which-key to execute a keybinding that already exists?
The text was updated successfully, but these errors were encountered: