Home > Mobile >  VSCode Focus Active Editor Group when explorer is Focused Not Working
VSCode Focus Active Editor Group when explorer is Focused Not Working

Time:02-19

In VSCode 1.64.1 on Windows, I'm trying to create some conditional shortcuts for focusing.

When the file explorer is not focused I would like ctrl 0 to focus the active editor group. When the active editor group is focused, I would like ctrl 0 to focus the explorer. I tried the following, but it only partially works.

Currently, hitting ctrl 0 will focus the explorer, but hitting ctrl 0 again when the explorer is focused does not focus the active editor group as desired:

//keybindings.json
  {
    "key": "ctrl 0",
    "command": "workbench.action.focusActiveEditorGroup",
    "when": "!editorTextFocus"
  },
  {
    "key": "ctrl 0",
    "command": "workbench.action.focusSideBar",
    "when": "!explorerFocus"
  }

CodePudding user response:

I don't see a explorerFocus context key. The below does work:

{
  "key": "ctrl 0",
  "command": "workbench.action.focusActiveEditorGroup",
  "when": "!editorTextFocus"
},
{
  "key": "ctrl 0",
  "command": "workbench.action.focusSideBar",
  "when": "!filesExplorerFocus"                  // change here
}

Apparently when you use a non-existent context key that when clause is not evaluated at all - as if it wasn't there. And since evaluation of the keybindings is from the bottom of the file up - first one from bottom wins - your focusActiveEditorGroup command will never be seen.

  • Related