在Atom编辑器中:如何使用箭头键在树中导航时保持在侧边栏焦点内

时间:2016-04-12 15:07:41

标签: atom-editor

我可以用 ctrl - \ (Linux / Windows)打开TreeView并获得焦点。此时我可以使用键盘上的箭头键导航,但只有按下输入和失去焦点,我才能看到所选的文件。

有没有办法继续专注于TreeView并启用了箭头键导航,并且当每个新文件都被导航时,编辑器会自动切换到该选项卡或打开一个打开该文件的新选项卡?

除了相反的方向外,功能类似于synced-sidebar Package,即您可以使用箭头键导航TreeView,而标签视图则会改变。

3 个答案:

答案 0 :(得分:1)

您可以将以下代码添加到init.coffee文件中:

atom.commands.add '.tree-view', 'tree-view:preview', ->
    for panel in atom.workspace.getLeftPanels()
        if panel.item.constructor.name == "TreeView"
            entry = panel.item.selectedEntry()
            if entry.classList[0] == "directory"
              entry.toggleExpansion()
              return
            else
              atom.workspace.open(entry.getPath(), pending: true, activatePane: false)
              return

之后,您可以通过向keymap.cson文件添加新的键映射来设置要执行的代码,如下所示:

'.tree-view':
  'right': 'tree-view:preview'

使用向右箭头将打开树视图中的文件和目录,而无需将焦点移动到编辑器。我建议您在准备好编辑文件后使用enter来切换焦点。

答案 1 :(得分:1)

不幸的是,A. Campbell's solution似乎不起作用;它在右箭头按下时被调用,但似乎没有任何作用。

对于其他在这里寻找解决方案的人,有ThomasChef的a long-opened github issue with a working answer

将其放在您的 init.coffee 中:(注意空格...)

atom.commands.add '.tree-view', 'custom:expand-item-down': ->
  fs = require 'fs'
  item = atom.workspace.getActivePaneItem()
  atom.commands.dispatch(item.element, 'core:move-down')
  if fs.lstatSync(item.selectedPath).isDirectory()
    return
  else
    item.openSelectedEntry(pending: true, activatePane: false)
    return
atom.commands.add '.tree-view', 'custom:expand-item-up': ->
  fs = require 'fs'
  item = atom.workspace.getActivePaneItem()
  atom.commands.dispatch(item.element, 'core:move-up')
  if fs.lstatSync(item.selectedPath).isDirectory()
    return
  else
    item.openSelectedEntry(pending: true, activatePane: false)
    return

并将其放在您的 keymap.cson 中:

'.tree-view':
  'down': 'custom:expand-item-down',
  'up': 'custom:expand-item-up'

答案 2 :(得分:0)

切换打开&关闭侧边栏树视图 CTRL + \

对于边栏和编辑页面的移动焦点 ALT + \

针对GNU / Linux的Atom进行了测试。

如果我的回答与您的问题无关,我很抱歉。

enter image description here