-
Notifications
You must be signed in to change notification settings - Fork 29.4k
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
'When' clauses are ignored for all commands in global menu #35225
Comments
@sandy081 What is this issue: |
@monk-time The |
I am not the issue author, but previous title was more precise: it's not limited to This works: {
"key": "ctrl+shift+8",
"command": "editor.action.insertSnippet",
"when": "editorLangId == 'javascript'"
} This doesn't: {
"key": "ctrl+shift+9",
"command": "workbench.action.togglePanel",
"when": "editorLangId == 'javascript'"
} Is this a known issue? All |
@jrieken The poster above is right, and I admit I could've made it clearer: when I was testing this, all clauses that I've tried were ignored. As I wrote in Step 1, I'll change the title back if you don't mind. |
Is this issue related #26318? |
You most likely tested with when-clauses that are only set inside an editor. There can be multiple editors at the same time (side by side, nested, diff etc.) and therefore multiple (nested) containers for context keys exist. The |
@jrieken, I don't have time to understand this undocumented local/global scope distinction, but this issue is about 'when' clauses that don't work as documented. Since it doesn't seem like you have tried to reproduce what I've described in the OP, I took the fresh Insiders build and put a simple action into
I create a new file, set the cursor to the main and only editor, debug mode is obviously not active, I hit If you are talking about some other issue, please stop changing this one into something that is not related to it and open another issue. Sorry, but I am getting really frustrated here. |
Can you find even 1 when context for which It ignores: |
@monk-time I am sorry, I mis read that and though about the opposite. I believe the problem is that those command appear in the global menu (with their assigned shortcut) and that therefore they are bypassing our context key checks... It's actually not us handling the keybinding at that point... Needs some thinking |
Yep, command is being called by global menu, not the keybindings service.... @bpasero Is this something new? |
Blocked by dynamic menus still not being enabled on macOS and Linux. |
As discussed this will be unblocked debt week in october |
Still works:
VS Code version: Code - Insiders 1.29.0-insider (d7ac6e8, 2018-11-01T06:11:43.390Z) |
sorry, my fixes actually bring back the behavior described here. the behavior of keybindings working out of context needs to be fixed in the keybindingservice because currently thoughts @alexandrudima |
@sbatten As we are all aware from multiple discussions on this topic, contexts are different depending on where the focus sits. I can implement a new method in |
@alexandrudima this iteration, I have made some improvements that greatly reduce the amount of updates the menu based on context. My current view is that the global application menu reflects the global context so enablement/disablement/keybindings must be based on context keys in the global scope. Thoughts? |
That is also incorrect, but in a different, more subtle way, and arguably would make things a lot worse. Before jumping to implement something worse, let's look at the problem. Take, for example, the Selection menu: Now let's look at a default keybinding from there: { "key": "shift+alt+up", "command": "editor.action.copyLinesUpAction",
"when": "editorTextFocus && !editorReadonly" },
Also, I think this bug affects only the native menu, because in the native menu case the menu itself (Electron via C++ code) listens to those keybindings and executes the menu item directly, outside of our logic. For custom menus, this is no longer a problem. I think there are two possible correct fixes:
|
We might be able to know that. I have tested mac and clicking vs keyboard shortcuts can be differentiated by the event - it's only partial but when pressing |
This was more of a statement of how I think things should be not necessarily how they are, but I agree this should be fleshed out. With this view actually in place, it limits the menu updates to relevant updates only for enablement/disablement/keybindings thanks to the support in @jrieken's menu model. For keybindings, we could fix this issue by trying to update the menu on every focus change, but that seems excessive. We also would still run into this issue with enablement/disablement, however. Keybindings get resolved for the menu each time it is updated. Enablement/Disablement does not. The context is set once when the menus are created in the model.
This makes me ask the question why the context service doesn't support evaluating against the current context based on focus if that's what matters instead of being required to track focus around. If I could set a flag on the context service to do this before handing it to the menu model and the keybinding service could use that when evaluating keybinds, it could work. Yes, I am coupling two issues but they are both related to resolving commands against a focused context. |
Key bindings for commands that toggle sidebar or panel visibility ignore 'when' clause contexts, making it impossible to limit them to certain contexts.
Use case: some shortcut schemes (e.g. Intellij IDEA) have a shortcut to hide current active sidebar or panel, and a VScode extension that provides such keybindings wants to recreate this functionality through a shortcut that toggles panels and the sidebar only when they are active, essentially turning a toggle into a closer. But since 'when' clause contexts for these actions always evaluate to true, the shortcuts become globally active and act as toggles. And while the last three shortcuts from that snippet are replaceable with a global shortcut for
workbench.action.closePanel
, there is no corresponding action to close (not toggle) the sidebar.Steps to reproduce:
ctrl+l
, and a context that would be inactive during the next steps, e.g.parameterHintsVisible
.keybindings.json
:ctrl+l
.Expected result: nothing should happen, the 'when' clause evaluates to false so the shortcut should be disabled.
Actual result: the shortcut works, the relevant panel/sidebar visibility is toggled.
The text was updated successfully, but these errors were encountered: