Shortcut with multiple command in VSCode

家住魔仙堡 提交于 2021-01-24 07:44:19

问题


I have an existing shortcut which maximize the terminal window,

{
        "key": "ctrl+`",
        "command": "workbench.action.toggleMaximizedPanel"
}

I would like to add an additional command to the shortcut to shift the focus to the terminal window when it is maximized and back to editor window when it is minimized. is this possible in vscode?


回答1:


I think you will have to use a macro extension like multi-command to run multiple commands with one keybinding. Once you have installed multi-command, in your settings.json:

  "multiCommand.commands": [

  {
      "command": "multiCommand.toggleTerminalAndFocusTerminal",

      "sequence": [
        "workbench.action.toggleMaximizedPanel",
        "workbench.action.terminal.focus",
      ]
    },

    {
      "command": "multiCommand.toggleTerminalAndFocusEditor",

      "sequence": [
        "workbench.action.toggleMaximizedPanel",
        "workbench.action.focusActiveEditorGroup",
      ]
    }
],

and then these keybindings:

{
  "key": "ctrl+`",
  "command": "extension.multiCommand.execute",
  "args": { "command": "multiCommand.toggleTerminalAndFocusTerminal" },
  "when": "!terminalFocus"
},

{
  "key": "ctrl+`",
  "command": "extension.multiCommand.execute",
  "args": { "command": "multiCommand.toggleTerminalAndFocusEditor" },
  "when": "terminalFocus"
},

So the same keybinding, Ctrl-backTick will trigger one of the two commands depending on whether the terminal has focus - note the "when": "!terminalFocus" meaning when the terminal does not have focus.



来源:https://stackoverflow.com/questions/55160717/shortcut-with-multiple-command-in-vscode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!