diff --git a/keymaps/tree-view.cson b/keymaps/tree-view.cson index e591f8ce..08c943c0 100644 --- a/keymaps/tree-view.cson +++ b/keymaps/tree-view.cson @@ -14,7 +14,7 @@ 'cmd-c': 'tree-view:copy' 'cmd-x': 'tree-view:cut' 'cmd-v': 'tree-view:paste' - 'ctrl-f': 'tree-view:expand-directory' + 'ctrl-f': 'tree-view:expand-item' 'ctrl-b': 'tree-view:collapse-directory' 'cmd-k right': 'tree-view:open-selected-entry-right' 'cmd-k l': 'tree-view:open-selected-entry-right' @@ -57,9 +57,9 @@ 'ctrl-9': 'tree-view:open-selected-entry-in-pane-9' '.tree-view': - 'right': 'tree-view:expand-directory' - 'ctrl-]': 'tree-view:expand-directory' - 'l': 'tree-view:expand-directory' + 'right': 'tree-view:expand-item' + 'ctrl-]': 'tree-view:expand-item' + 'l': 'tree-view:expand-item' 'left': 'tree-view:collapse-directory' 'ctrl-[': 'tree-view:collapse-directory' 'alt-ctrl-]': 'tree-view:recursive-expand-directory' diff --git a/lib/tree-view.coffee b/lib/tree-view.coffee index 995ccc38..457a299c 100644 --- a/lib/tree-view.coffee +++ b/lib/tree-view.coffee @@ -109,7 +109,7 @@ class TreeView extends View 'core:page-down': => @pageDown() 'core:move-to-top': => @scrollToTop() 'core:move-to-bottom': => @scrollToBottom() - 'tree-view:expand-directory': => @expandDirectory() + 'tree-view:expand-item': => @openSelectedEntry(pending: true, true) 'tree-view:recursive-expand-directory': => @expandDirectory(true) 'tree-view:collapse-directory': => @collapseDirectory() 'tree-view:recursive-collapse-directory': => @collapseDirectory(true) @@ -205,7 +205,7 @@ class TreeView extends View when 1 @selectEntry(entry) if entry instanceof FileView - @openSelectedEntry(pending: true) + atom.workspace.open(entry.getPath(), pending: true) else if entry instanceof DirectoryView entry.toggleExpansion(isRecursive) when 2 @@ -368,7 +368,9 @@ class TreeView extends View @scrollToEntry(@selectedEntry()) expandDirectory: (isRecursive=false) -> - @selectedEntry()?.expand?(isRecursive) + selectedEntry = @selectedEntry() + if selectedEntry instanceof DirectoryView + selectedEntry.expand(isRecursive) collapseDirectory: (isRecursive=false) -> selectedEntry = @selectedEntry() @@ -378,12 +380,19 @@ class TreeView extends View directory.collapse(isRecursive) @selectEntry(directory) - openSelectedEntry: (options) -> + openSelectedEntry: (options={}, expandDirectory=false) -> selectedEntry = @selectedEntry() if selectedEntry instanceof DirectoryView - selectedEntry.toggleExpansion() + if expandDirectory + selectedEntry.expand() + else + selectedEntry.toggleExpansion() else if selectedEntry instanceof FileView - atom.workspace.open(selectedEntry.getPath(), options) + uri = selectedEntry.getPath() + item = atom.workspace.getActivePane()?.itemForURI(uri) + if item? and not options.pending + item.terminatePendingState?() + atom.workspace.open(uri, options) openSelectedEntrySplit: (orientation, side) -> selectedEntry = @selectedEntry() diff --git a/spec/tree-view-spec.coffee b/spec/tree-view-spec.coffee index 0b60c68c..fd316180 100644 --- a/spec/tree-view-spec.coffee +++ b/spec/tree-view-spec.coffee @@ -942,25 +942,6 @@ describe "TreeView", -> _.times entryCount, -> atom.commands.dispatch(treeView.element, 'core:move-up') expect(treeView.scrollTop()).toBe 0 - describe "tree-view:expand-directory", -> - describe "when a directory entry is selected", -> - it "expands the current directory", -> - subdir = root1.find('.directory:first') - subdir.click() - subdir[0].collapse() - - expect(subdir).not.toHaveClass 'expanded' - atom.commands.dispatch(treeView.element, 'tree-view:expand-directory') - expect(subdir).toHaveClass 'expanded' - - describe "when a file entry is selected", -> - it "does nothing", -> - waitsForFileToOpen -> - root1.find('.file').click() - - runs -> - atom.commands.dispatch(treeView.element, 'tree-view:expand-directory') - describe "tree-view:recursive-expand-directory", -> describe "when an collapsed root is recursively expanded", -> it "expands the root and all subdirectories", -> @@ -1056,8 +1037,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 +1047,36 @@ describe "TreeView", -> item = atom.workspace.getActivePaneItem() expect(item.getPath()).toBe atom.project.getDirectories()[0].resolve('tree-view.js') expect(atom.views.getView(item)).toHaveFocus() + if atom.workspace.buildTextEditor().isPending? + expect(item.isPending()).toBe false + + if atom.workspace.buildTextEditor().isPending? + it "terminates pending state for items that are pending", -> + jasmine.attachToDOM(workspaceElement) + + file = root1.find('.file:contains(tree-view.js)')[0] + treeView.selectEntry(file) + + waitsForFileToOpen -> + atom.commands.dispatch(treeView.element, 'tree-view:expand-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() + + file = root1.find('.file:contains(tree-view.js)')[0] + treeView.selectEntry(file) + + waitsForFileToOpen -> + atom.commands.dispatch(treeView.element, 'tree-view:open-selected-entry') + + runs -> + 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 +1143,39 @@ describe "TreeView", -> atom.commands.dispatch(treeView.element, command) expect(atom.workspace.getActivePaneItem()).toBeUndefined() + describe "tree-view:expand-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:expand-item') + + runs -> + item = atom.workspace.getActivePaneItem() + expect(item.getPath()).toBe atom.project.getDirectories()[0].resolve('tree-view.js') + if atom.workspace.buildTextEditor().isPending? + 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:expand-item') + expect(subdir).toHaveClass 'expanded' + + describe "when nothing is selected", -> + it "does nothing", -> + atom.commands.dispatch(treeView.element, 'tree-view:expand-item') + expect(atom.workspace.getActivePaneItem()).toBeUndefined() + describe "opening in existing split panes", -> beforeEach -> jasmine.attachToDOM(workspaceElement)