Vscode: Ability to Toggle SideBar panels with the same shortcut

Created on 22 Nov 2016  路  2Comments  路  Source: microsoft/vscode

Not sure if you/others will agree but it would be nice to be able to open (collapsed) SideBar panel (eg. Explorer) and close it with the same shortcut.

I mostly work with hidden Activity Bar and Side bar and when I need for example Explorer for a moment:

  1. I press Cmd+Shift+E (my hand stays over that key combination)
  2. I click the file with second hand and I'm ready to close the panel
  3. But pressing the same Cmd+Shift+E combination does not toggle/close Panel - I need to switch to Cmd+B to close

Maybe additional setting or logic that if panel got open due to shortcut (while hidden) one can close with the same key combinations - seems the most natural

*question

Most helpful comment

I think the argument against this (and one I'd go along with) is that if you even if you have the explorer sidebar open, you might want to focus it, and it's good to know that ctrl+shift+e will always do this whether it's open or not.

Maybe you could argue that if the panel has focus, then the shortcut should close it, but that's making the behavior a bit complicated

There is a solution for your particular case though. You can add custom keybindings that only trigger in certain situations through the when field of the keybinding entry. This is documented at the bottom of the page at https://code.visualstudio.com/docs/customization/keybindings. There doesn't seem to be an existing when option for when the explorer panel has focus, but you can achieve the same thing by saying: "when the editor doesn't have focus".

It's a bit hacky but if you add this to your keybindings.json file, you should get the behavior you want:

{ 
  "key": "ctrl+shift+e",
  "when": "!editorTextFocus", 
  "command": "workbench.action.toggleSidebarVisibility"
}

All 2 comments

I think the argument against this (and one I'd go along with) is that if you even if you have the explorer sidebar open, you might want to focus it, and it's good to know that ctrl+shift+e will always do this whether it's open or not.

Maybe you could argue that if the panel has focus, then the shortcut should close it, but that's making the behavior a bit complicated

There is a solution for your particular case though. You can add custom keybindings that only trigger in certain situations through the when field of the keybinding entry. This is documented at the bottom of the page at https://code.visualstudio.com/docs/customization/keybindings. There doesn't seem to be an existing when option for when the explorer panel has focus, but you can achieve the same thing by saying: "when the editor doesn't have focus".

It's a bit hacky but if you add this to your keybindings.json file, you should get the behavior you want:

{ 
  "key": "ctrl+shift+e",
  "when": "!editorTextFocus", 
  "command": "workbench.action.toggleSidebarVisibility"
}

@stkb That works like a charm. Thanks so much

Was this page helpful?
0 / 5 - 0 ratings