diff --git a/keymaps/tree-view.cson b/keymaps/tree-view.cson index e591f8ce..de17f27b 100644 --- a/keymaps/tree-view.cson +++ b/keymaps/tree-view.cson @@ -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' diff --git a/lib/tree-view.coffee b/lib/tree-view.coffee index 995ccc38..86e79e52 100644 --- a/lib/tree-view.coffee +++ b/lib/tree-view.coffee @@ -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() @@ -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) diff --git a/spec/tree-view-spec.coffee b/spec/tree-view-spec.coffee index 0b60c68c..c47ad312 100644 --- a/spec/tree-view-spec.coffee +++ b/spec/tree-view-spec.coffee @@ -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') @@ -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", -> @@ -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)