简体   繁体   English

在 VSCode 中使用多个命令的快捷方式

[英]Shortcut with multiple command in VSCode

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?这在 vscode 中可能吗?

I think you will have to use a macro extension like multi-command to run multiple commands with one keybinding.我认为您将不得不使用像multi-command这样的宏扩展来通过一个键绑定运行多个命令。 Once you have installed multi-command, in your settings.json:安装多命令后,在 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.因此,相同的键绑定, Ctrl - backTick将根据终端是否有焦点触发两个命令之一 - 请注意"when": "!terminalFocus"表示终端没有焦点时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM