0

我想cmd+1在侧边栏显示(如果关闭)和侧边栏打开时交替显示,关闭它。

如果关闭:{ "keys": ["super+1"], "command": "reveal_in_side_bar"}

如果打开:{ "keys": ["super+1"], "command": "toggle_side_bar" }

我不知道该怎么做if。谢谢

4

1 回答 1

2

据我所知,没有内置的键绑定上下文可以用来判断侧边栏是打开还是关闭。但这可以使用Python API轻松完成,特别是使用window.is_sidebar_visible()并且还可以创建自定义键绑定上下文。

从工具菜单中,导航到开发人员 > 新插件。然后将视图的内容替换为:

import sublime, sublime_plugin

class SidebarContextListener(sublime_plugin.EventListener):
    def on_query_context(self, view, key, operator, operand, match_all):
        if key != 'sidebar_visible' or not (operand in ('reveal', 'toggle')):
            return None
        visible = view.window().is_sidebar_visible()
        if operand == 'toggle' and visible:
            return True
        if operand == 'reveal' and not visible:
            return True
        return None

并将其保存在 ST 建议 ( Packages/User)的文件夹中sidebar_context.py- 扩展名很重要,名称不重要。

现在,我们可以在您的键绑定中使用它,例如:

{ "keys": ["super+1"], "command": "toggle_side_bar", "context":
    [
        { "key": "sidebar_visible", "operand": "toggle" },
    ],
},

{ "keys": ["super+1"], "command": "reveal_in_side_bar", "context":
    [
        { "key": "sidebar_visible", "operand": "reveal" },
    ],
},
于 2018-05-12T10:17:49.397 回答