首页 > 解决方案 > 创建一个快捷方式来切换 VSCode 中的大纲视图

问题描述

我已经成功地为显示大纲面板的 outline.focus 创建了一个快捷键。我正在寻找切换行为。

现有

{
    "key": "ctrl+alt+o",
    "command": "outline.focus",
    "when": "editorTextFocus"
}

可能吗??

标签: visual-studio-codevscode-settingskeymapping

解决方案


这会将焦点切换到大纲视图并折叠大纲视图中所有打开的树项目。

[方便的选项:选项视图中的“跟随光标”选项(单击...选项)。]

{
  "key": "ctrl+alt+o",
  "command": "list.collapseAll",   // Ctrl+LeftArrow also does this
                                   // Space will open the current tree item
                                   // left/right arrows will open/close item
  "when": "outline.active"
},

{
  "key": "ctrl+alt+o",
  "command": "outline.focus",
  "when": "editorTextFocus"
},

因此,单击Ctrl+ Alt+O一次会将焦点转移到大纲视图,然后单击Ctrl+ Alt+O次会折叠所有打开的项目。由于某种原因没有list.expandAll命令,因此您无法切换它们。

如果您愿意,可以将这些组合成一个宏命令,因此只需点击一个组合键即可聚焦大纲视图并全部折叠。如果你想看,请告诉我。


推荐阅读