我正在尝试为 Atom 编辑器编写一个初始化脚本,以添加自定义命令,以便能够使用一个组合键(而不是两个组合键)在树视图中显示当前打开的编辑器文件。
这是一个示例代码(它使一些东西有所不同),以明确它通常的外观。
atom.commands.add 'atom-editor', 'custom:cut-line', ->
editor = atom.workspace.getActiveEditor()
editor.selectLine()
editor.cutSelectedText()
我需要的两个命令不应该发送到editor
,但是到tree-view
。这是两个命令:
tree-view:toggle-focus
tree-view:reveal-active-file
我想我必须做与上面类似的事情,比如getActiveTreeView
或类似的东西。我试图用谷歌搜索它,但它似乎并不明显。有人知道该怎么做吗?
它可能看起来像这样:
atom.commands.add 'atom-editor', 'custom:show-active-file', ->
tree-view.toggle-focus()
tree-view.reveal-active-file()
您可以使用atom.commands.dispatch()
当获取要发送命令的对象时发送命令的方法很困难。对于您的情况,您可以使用:
atom.commands.add 'atom-editor', 'custom:show-active-file', ->
atom.commands.dispatch(atom.workspaceView.element, 'tree-view:toggle-focus')
atom.commands.dispatch(atom.workspaceView.element, 'tree-view:reveal-active-file')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)