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

Commit 5a9656b

Browse files
committed
Merge pull request #645 from atom/ks-delete-entry-properly
Delete entry from expansion state property
2 parents 4eea2f1 + 22756a0 commit 5a9656b

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

lib/directory.coffee

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,13 @@ class Directory
229229
for name, entry of removedEntries
230230
entriesRemoved = true
231231
entry.destroy()
232-
delete @entries[name]
233-
delete @expansionState[name]
232+
233+
if @entries.hasOwnProperty(name)
234+
delete @entries[name]
235+
236+
if @expansionState.entries.hasOwnProperty(name)
237+
delete @expansionState.entries[name]
238+
234239
@emitter.emit('did-remove-entries', removedEntries) if entriesRemoved
235240

236241
if newEntries.length > 0

spec/tree-view-spec.coffee

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2657,6 +2657,36 @@ describe "TreeView", ->
26572657
expect(atom.notifications.getNotifications()[0].getMessage()).toContain 'Opening folder in Finder failed'
26582658
expect(atom.notifications.getNotifications()[0].getDetail()).toContain 'ENOENT'
26592659

2660+
describe "when reloading a directory with deletions and additions", ->
2661+
it "does not throw an error (regression)", ->
2662+
projectPath = temp.mkdirSync('atom-project')
2663+
entriesPath = path.join(projectPath, 'entries')
2664+
2665+
fs.mkdirSync(entriesPath)
2666+
atom.project.setPaths([projectPath])
2667+
treeView.roots[0].expand()
2668+
expect(treeView.roots[0].directory.serializeExpansionState()).toEqual
2669+
isExpanded: true
2670+
entries:
2671+
entries:
2672+
isExpanded: false
2673+
entries: {}
2674+
2675+
fs.removeSync(entriesPath)
2676+
treeView.roots[0].reload()
2677+
expect(treeView.roots[0].directory.serializeExpansionState()).toEqual
2678+
isExpanded: true
2679+
entries: {}
2680+
2681+
fs.mkdirSync(path.join(projectPath, 'other'))
2682+
treeView.roots[0].reload()
2683+
expect(treeView.roots[0].directory.serializeExpansionState()).toEqual
2684+
isExpanded: true
2685+
entries:
2686+
other:
2687+
isExpanded: false
2688+
entries: {}
2689+
26602690
describe "Dragging and dropping files", ->
26612691
beforeEach ->
26622692
rootDirPath = fs.absolute(temp.mkdirSync('tree-view'))

0 commit comments

Comments
 (0)