I can open the TreeView with ctrl-\ (Linux/Windows) and get focus. At this point I can navigate around with the arrow keys on the keyboard, but only by hitting enter and losing focus, am I able to see the file which was selected.
Is there a way to remain focused on the TreeView and with arrow key navigation enabled, and as each new file is navigated over, the editor will automatically switch to that tab or open a new tab with that file open?
The functionality would be similar to the synced-sidebar Package except in the opposite direction, i.e., you would navigate the TreeView with the arrow keys and the tab view would change instead.
You could add the following code to your init.coffee
file:
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
After which you can set the code to execute by adding a new keymap to the keymap.cson
file, like so:
'.tree-view':
'right': 'tree-view:preview'
Using the right arrow will open files and directories in the tree view without moving focus to the editor. I'd suggest using enter to toggle focus once you're ready to edit a file.
Unfortunately, A. Campbell's solution doesn't seem to work; it's called on right-arrow press, but doesn't appear to do anything.
For others ending up here searching for a solution, there's a long-opened github issue with a working answer by ThomasChef.
Put this in your init.coffee: (mind the spaces...)
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
and put this in your keymap.cson:
'.tree-view':
'down': 'custom:expand-item-down',
'up': 'custom:expand-item-up'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With