Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
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:activate-item'
'ctrl-]': 'tree-view:expand-directory'
'l': 'tree-view:expand-directory'
'left': 'tree-view:collapse-directory'
Expand Down
8 changes: 8 additions & 0 deletions lib/tree-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class TreeView extends View
'core:page-down': => @pageDown()
'core:move-to-top': => @scrollToTop()
'core:move-to-bottom': => @scrollToBottom()
'tree-view:activate-item': => @activateItem()
'tree-view:expand-directory': => @expandDirectory()
'tree-view:recursive-expand-directory': => @expandDirectory(true)
'tree-view:collapse-directory': => @collapseDirectory()
Expand Down Expand Up @@ -367,6 +368,13 @@ class TreeView extends View

@scrollToEntry(@selectedEntry())

activateItem: ->
classList = @selectedEntry().classList
if classList.contains('directory')
@expandDirectory()
else if classList.contains('file')
@openSelectedEntry(pending: true)

expandDirectory: (isRecursive=false) ->
@selectedEntry()?.expand?(isRecursive)

Expand Down
37 changes: 35 additions & 2 deletions spec/tree-view-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,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()
file = root1.find('.file:contains(tree-view.js)')[0]
treeView.selectEntry(file)

waitsForFileToOpen ->
atom.commands.dispatch(treeView.element, 'tree-view:open-selected-entry')
Expand All @@ -1066,6 +1066,7 @@ describe "TreeView", ->
item = atom.workspace.getActivePaneItem()
expect(item.getPath()).toBe atom.project.getDirectories()[0].resolve('tree-view.js')
expect(atom.views.getView(item)).toHaveFocus()
expect(item.isPending()).toBe false

describe "when a directory is selected", ->
it "expands or collapses the directory", ->
Expand Down Expand Up @@ -1132,6 +1133,38 @@ describe "TreeView", ->
atom.commands.dispatch(treeView.element, command)
expect(atom.workspace.getActivePaneItem()).toBeUndefined()

describe "tree-view:activate-item", ->
describe "when a file is selected", ->
it "opens the file in the editor in pending state and focuses it", ->
jasmine.attachToDOM(workspaceElement)

file = root1.find('.file:contains(tree-view.js)')[0]
treeView.selectEntry(file)

waitsForFileToOpen ->
atom.commands.dispatch(treeView.element, 'tree-view:activate-item')

runs ->
item = atom.workspace.getActivePaneItem()
expect(item.getPath()).toBe atom.project.getDirectories()[0].resolve('tree-view.js')
expect(item.isPending()).toBe true
expect(atom.views.getView(item)).toHaveFocus()

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

expect(subdir).not.toHaveClass 'expanded'
atom.commands.dispatch(treeView.element, 'tree-view:activate-item')
expect(subdir).toHaveClass 'expanded'

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

describe "opening in existing split panes", ->
beforeEach ->
jasmine.attachToDOM(workspaceElement)
Expand Down