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

Open pending file on right arrow keypress #714

Merged
merged 3 commits into from
Feb 1, 2016
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
8 changes: 4 additions & 4 deletions keymaps/tree-view.cson
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
21 changes: 15 additions & 6 deletions lib/tree-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
86 changes: 65 additions & 21 deletions spec/tree-view-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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", ->
Expand Down Expand Up @@ -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')
Expand All @@ -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", ->
Expand Down Expand Up @@ -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)
Expand Down