-
Notifications
You must be signed in to change notification settings - Fork 28.7k
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
Cmd+K for clearing the terminal doesn't work #43623
Comments
@fabiospampinato this works for me in both the latest VSCode and Insiders. Can you specify which one are you using?
How did you reach to this conclusion? |
@shobhitchittora I've added some info about the VSC version I'm using to my original post. I'm pretty surprised this works for you. I think it never worked for me, it was for sure broken in the past ~5 releases for me.
There are plenty of keybindings listening for shortcuts like |
@fabiospampinato this is a common issue, it happens when either you define a ctrl+k chord keybinding or an extension does it. The only workaround currently is to redefine the cmd+k keybinding at a higher level (user keybindings.json). Adding this again to the bottom of your keybindings.json should fix the problem: { "key": "cmd+k", "command": "workbench.action.terminal.clear",
"when": "terminalFocus" }, This is the best we can do at the moment due to how the keybindings system works. It's a little hacky that it works at all, a special case was added just to get terminal clear working. |
@Tyriar Thanks for the info. I don't think this can be considered fixed though, I'm still having a few problems: Multiple commands triggeredMy [
{ "key": "cmd+k cmd+b", "command": "workbench.action.toggleSidebarVisibility" },
{ "key": "cmd+k", "command": "workbench.action.terminal.clear", "when": "terminalFocus" }
]
Order taken into accountMy [
{ "key": "cmd+k", "command": "workbench.action.terminal.clear", "when": "terminalFocus" },
{ "key": "cmd+k cmd+b", "command": "workbench.action.toggleSidebarVisibility" }
]
|
So most of you said is how I expect it to work currently, except for this:
I cannot repro this but it's a bug if it happens. Any more steps on how to repro would be good. But yeah it's a bit confusing, currently the behavior is chord keybindings always win unless there is a keybinding with a higher priority than them. We also want to make it easy for users to unbind cmd+k as some users will want to use chord keybindings even when the terminal is focused. @alexandrudima it's been a while since you looked at this, has there been any movement around the keybindings system that would make it easier for cmd+k to get a higher priority due to the |
If someone adds a user keybinding for The keybinding system is a rule-based system, where rules are evaluated in the order that users write them. See https://code.visualstudio.com/docs/getstarted/keybindings#_keyboard-rules . Even if some of the There are no plans whatsoever to change this. |
This is exactly what I'm doing:
[
{ "key": "cmd+k cmd+b", "command": "workbench.action.toggleSidebarVisibility" },
{ "key": "cmd+k", "command": "workbench.action.terminal.clear", "when": "terminalFocus" }
]
I think at least it should be stated in the docs that if you add any keybinding listening for The lack of a timeout for chord shortcuts is also confusing to me, I was expecting that after doing a I think @Tyriar was referring to the simpler case where a keybinding doesn't have a |
@fabiospampinato There is a default keybinding of So when you do
Also, most likely there is no message You have a point, that a chord should no longer be waited for after e.g. 1 minute or after focusing out of vscode. i.e. the state should be cleared. But that does not mean |
This would be fine if it just worked like this, but even with no { "key": "cmd+k m", "command": "workbench.action.editor.changeLanguageMode" } And now the keybinding that everyone knows for the terminal doesn't work. I think we discussed when you were over here that forcing then when to have higher priority would break many other keybindings so maybe a fix for this would be a priority similar to
Ah this makes sense. |
|
I thought of a better example. (p1). I like to drink beer when it is hot outside. (p2) implies (p1) even if (p2) omits the when clause. |
@alexandrudima but there's still the problem that cmd+k breaks all of a sudden when users install extensions or add seemingly innocuous keybindings when we want it to always be active unless explicitly disabled. (p1). I really like to drink beer when it is hot outside. |
Leaving beer aside for a moment, look at what happens with this [
{ "key": "cmd+k cmd+b", "command": "workbench.action.toggleStatusbarVisibility" },
{ "key": "cmd+k", "command": "workbench.action.terminal.clear", "when": "terminalFocus" }
] I do cmd+k cmd+b and the statusbar doesn't get toggled, instead my terminal gets cleared and the sidebar gets toggled. If I reverse the order of those entries in the array then I can't clear the terminal with cmd+k anymore. Basically there's no way to do chord shortcuts while the terminal is in focus, if you also want cmd+k to clear the terminal. I'm not saying this is a huge deal, but it definitely doesn't look right to me. |
@fabiospampinato I don't see this changing, it would be weirder imo for it to clear the terminal and then toggle status bar visibility. if you use the chords a lot you can always unbind cmd+k and bind it to something else:
|
Yes, that is the default experience out of the box. Think of the keybinding service as a state machine. When you press a keybinding the keybinding service must make a decision from three options:
You can configure it to do anyone of these 3 things, but it cannot do two of those at the same time. It cannot both clear the terminal and enter chord mode when you are focused in the terminal and press cmd+k. Let's get back to the original problem. I write in { "key": "cmd+k cmd+c", "command": "editor.action.addCommentLine" }, And now I cannot clear terminal with cmd+k. My question is: so what? This is as designed. Our keybinding system allows to do it, and that is legal. If you don't know what editing Look, I can break a on my keyboard. I just added this to { "key": "a", "command":"type", "args": { "text":"b"} } Again, so what? I have the power, it is my responsibility to use it wisely and read the documentation to understand the consequences of what I am doing. @Tyriar if you believe cmd+k is often asked about, then please add an entry in the FAQ at https://code.visualstudio.com/docs/getstarted/keybindings#_common-questions so we can point people to it. You can also direct people to stack overflow for questions. |
VS Code version: Code 1.20.0 (c63189d, 2018-02-07T17:02:34.244Z)
OS version: Darwin x64 17.5.0
There's this object in my default keybindings (macOS):
It's supposed to clear the terminal on
cmd+k
, basically the same behaviour of the defaultTerminal.app
.This doesn't work though, since
cmd+k
is not considered a complete shortcut on its own and VSC will wait for another key/shortcut to complement it.I think a timeout should be implemented in the shortcuts handler, if no other key is pressed within N milliseconds execute what has been typed so far as a shortcut, in this case clear the terminal instead of waiting forever.
The text was updated successfully, but these errors were encountered: