Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

preview selected file on key 'right' #413

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion keymaps/tree-view.cson
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
'ctrl-9': 'tree-view:open-selected-entry-in-pane-9'

'.tree-view':
'right': 'tree-view:expand-directory'
'right': 'tree-view:preview-selected-entry'
'ctrl-]': 'tree-view:expand-directory'
'l': 'tree-view:expand-directory'
'left': 'tree-view:collapse-directory'
Expand Down
3 changes: 2 additions & 1 deletion lib/tree-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class TreeView extends View
'tree-view:recursive-expand-directory': => @expandDirectory(true)
'tree-view:collapse-directory': => @collapseDirectory()
'tree-view:recursive-collapse-directory': => @collapseDirectory(true)
'tree-view:preview-selected-entry': => @openSelectedEntry(false)
'tree-view:open-selected-entry': => @openSelectedEntry(true)
'tree-view:open-selected-entry-right': => @openSelectedEntryRight()
'tree-view:open-selected-entry-left': => @openSelectedEntryLeft()
Expand Down Expand Up @@ -376,7 +377,7 @@ class TreeView extends View
openSelectedEntry: (activatePane) ->
selectedEntry = @selectedEntry()
if selectedEntry instanceof DirectoryView
selectedEntry.toggleExpansion()
selectedEntry.expand()
else if selectedEntry instanceof FileView
atom.workspace.open(selectedEntry.getPath(), {activatePane})

Expand Down
46 changes: 37 additions & 9 deletions spec/tree-view-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -950,9 +950,8 @@ describe "TreeView", ->
it "opens the file in the editor and focuses it", ->
jasmine.attachToDOM(workspaceElement)

waitsForFileToOpen ->
root1.find('.file:contains(tree-view.js)').click()

selectEntry 'tree-view.js'

waitsForFileToOpen ->
atom.commands.dispatch(treeView.element, 'tree-view:open-selected-entry')

Expand All @@ -962,20 +961,49 @@ describe "TreeView", ->
expect(atom.views.getView(item)).toHaveFocus()

describe "when a directory is selected", ->
it "expands or collapses the directory", ->
subdir = root1.find('.directory').first()
subdir.click()
subdir[0].collapse()

it "expands the directory", ->
selectEntry 'dir1'
subdir = treeView.selectedEntry()
expect(subdir).not.toHaveClass 'expanded'
atom.commands.dispatch(treeView.element, 'tree-view:open-selected-entry')
expect(subdir).toHaveClass 'expanded'

describe "when nothing is selected", ->
it "does nothing", ->
atom.commands.dispatch(treeView.element, 'tree-view:open-selected-entry')
expect(atom.workspace.getActivePaneItem()).toBeUndefined()

describe "tree-view:preview-selected-entry", ->
describe "when a file is selected", ->
it "opens the file in the editor without focusing it", ->
jasmine.attachToDOM(workspaceElement)

selectEntry 'tree-view.js'

treeView.focus()
expect(treeView.list).toMatchSelector ':focus'

waitsForFileToOpen ->
atom.commands.dispatch(treeView.element, 'tree-view:preview-selected-entry')

runs ->
item = atom.workspace.getActivePaneItem()
expect(item.getPath()).toBe atom.project.getDirectories()[0].resolve('tree-view.js')
expect(atom.views.getView(item)).not.toHaveFocus()
expect(treeView.list).toMatchSelector ':focus'

describe "when a directory is selected", ->
it "expands the directory", ->
selectEntry 'dir1'
subdir = treeView.selectedEntry()

expect(subdir).not.toHaveClass 'expanded'
atom.commands.dispatch(treeView.element, 'tree-view:preview-selected-entry')
expect(subdir).toHaveClass 'expanded'

describe "when nothing is selected", ->
it "does nothing", ->
atom.commands.dispatch(treeView.element, 'tree-view:open-selected-entry')
atom.commands.dispatch(treeView.element, 'tree-view:preview-selected-entry')
expect(atom.workspace.getActivePaneItem()).toBeUndefined()

describe "opening in new split panes", ->
Expand Down