Skip to content

Commit da73935

Browse files
committed
Terminate pending state for pending item in openSelectedEntry
1 parent f48e6f6 commit da73935

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

lib/tree-view.coffee

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,19 @@ class TreeView extends View
379379
directory.collapse(isRecursive)
380380
@selectEntry(directory)
381381

382-
openSelectedEntry: (options, expandDirectory) ->
382+
openSelectedEntry: (options={}, expandDirectory=false) ->
383383
selectedEntry = @selectedEntry()
384384
if selectedEntry instanceof DirectoryView
385385
if expandDirectory
386386
@expandDirectory()
387387
else
388388
selectedEntry.toggleExpansion()
389389
else if selectedEntry instanceof FileView
390-
atom.workspace.open(selectedEntry.getPath(), options)
390+
uri = selectedEntry.getPath()
391+
item = atom.workspace.getActivePane()?.itemForURI(uri)
392+
if item? and not options.pending
393+
item.terminatePendingState?()
394+
atom.workspace.open(uri, options)
391395

392396
openSelectedEntrySplit: (orientation, side) ->
393397
selectedEntry = @selectedEntry()

spec/tree-view-spec.coffee

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,34 @@ describe "TreeView", ->
10691069
if atom.workspace.buildTextEditor().isPending?
10701070
expect(item.isPending()).toBe false
10711071

1072+
if atom.workspace.buildTextEditor().isPending?
1073+
it "terminates pending state for items that are pending", ->
1074+
jasmine.attachToDOM(workspaceElement)
1075+
1076+
file = root1.find('.file:contains(tree-view.js)')[0]
1077+
treeView.selectEntry(file)
1078+
1079+
waitsForFileToOpen ->
1080+
atom.commands.dispatch(treeView.element, 'tree-view:expand-item')
1081+
1082+
runs ->
1083+
item = atom.workspace.getActivePaneItem()
1084+
expect(item.getPath()).toBe atom.project.getDirectories()[0].resolve('tree-view.js')
1085+
expect(item.isPending()).toBe true
1086+
expect(atom.views.getView(item)).toHaveFocus()
1087+
1088+
file = root1.find('.file:contains(tree-view.js)')[0]
1089+
treeView.selectEntry(file)
1090+
1091+
waitsForFileToOpen ->
1092+
atom.commands.dispatch(treeView.element, 'tree-view:open-selected-entry')
1093+
1094+
runs ->
1095+
item = atom.workspace.getActivePaneItem()
1096+
expect(item.getPath()).toBe atom.project.getDirectories()[0].resolve('tree-view.js')
1097+
expect(atom.views.getView(item)).toHaveFocus()
1098+
expect(item.isPending()).toBe false
1099+
10721100
describe "when a directory is selected", ->
10731101
it "expands or collapses the directory", ->
10741102
subdir = root1.find('.directory').first()

0 commit comments

Comments
 (0)