我正在尝试为Atom编辑器编写一个init脚本,以便添加一个自定义命令,以便能够使用一个组合键而不是两个组合键在树视图中显示当前打开的编辑器文件。
这里有一个示例代码(它做了一些不同的事情),以明确它通常应该是什么样子的。
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()发布于 2014-12-01 22:40:54
当很难获得要发送命令的对象时,可以使用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')发布于 2019-07-04 21:03:33
不幸的是,李的答案不再正确了。在API的更改中,将atom.workspaceView的名称更改为atom.workspace。
因此,如果有人来到这里(当然问题和答案是“有点”旧的),这是当前的工作脚本。
atom.commands.add 'atom-editor', 'custom:show-active-file', ->
atom.commands.dispatch(atom.workspace.element, 'tree-view:toggle-focus')
atom.commands.dispatch(atom.workspace.element, 'tree-view:reveal-active-file')@Source
https://stackoverflow.com/questions/27224269
复制相似问题