如何在 Visual Studio 代码中使用相同的快捷方式隐藏和显示边栏

How to hide and show side bar with the same shortcut in Visual Studio code

我在 MacOS 上有以下 VS Code 快捷方式:

  {
    "key": "cmd+1",
    "command": "workbench.scm.focus"
  },

如果边栏不可见,这将聚焦源代码管理窗格并显示它。我现在想要的是在我再次单击 Cmd+1 并且 scm 窗格打开时隐藏侧边栏。现在我可以用 Cmd+B:

隐藏侧面板

有办法改变吗?我一直在尝试做一个有条件的捷径,但我没有找到方法。

我不确定我是否理解您的流程,但您是否看过 when 子句上下文?

在此处查找列表:https://code.visualstudio.com/api/references/when-clause-contexts#available-contexts

然后您可以使用 When 列中的那些:

  {
    "key": "cmd+1",
    "command": "workbench.scm.focus",
    "when": "!workbench.scm.visible"
  },
  {
    "key": "cmd+1",
    "command": "workbench.action.toggleSidebarVisibility",
    "when": "workbench.scm.visible"
  },