From dbbc15f453456bd84bd100c8915a8dbcf647dd36 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Wed, 4 Dec 2024 10:15:54 -0500 Subject: [PATCH] Fix failing `tree-view` specs --- packages/tree-view/lib/tree-view.js | 16 +++++++++++++--- .../tree-view/spec/tree-view-package-spec.js | 4 +++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/tree-view/lib/tree-view.js b/packages/tree-view/lib/tree-view.js index efc1b604cb..f90d51ea20 100644 --- a/packages/tree-view/lib/tree-view.js +++ b/packages/tree-view/lib/tree-view.js @@ -904,6 +904,17 @@ class TreeView { if (response === 0) { // Move to Trash let failedDeletions = []; let deletionPromises = []; + + // Since this goes async, all entries that correspond to paths we're + // about to delete will soon detach frmo the tree. So we should figure + // out ahead of time which element we're going to select when we're + // done. + let newSelectedEntry; + let firstSelectedEntry = selectedEntries[0]; + if (firstSelectedEntry) { + newSelectedEntry = firstSelectedEntry.closest('.directory:not(.selected)'); + } + for (let selectedPath of selectedPaths) { // Don't delete entries which no longer exist. This can happen, for // example, when @@ -943,9 +954,8 @@ class TreeView { ); } - let firstSelectedEntry = selectedEntries[0]; - if (firstSelectedEntry) { - this.selectEntry(firstSelectedEntry.closest('.directory:not(.selected)')); + if (newSelectedEntry) { + this.selectEntry(newSelectedEntry); } if (atom.config.get('tree-view.squashDirectoryNames')) { diff --git a/packages/tree-view/spec/tree-view-package-spec.js b/packages/tree-view/spec/tree-view-package-spec.js index 2f20e3416b..0d0e1260aa 100644 --- a/packages/tree-view/spec/tree-view-package-spec.js +++ b/packages/tree-view/spec/tree-view-package-spec.js @@ -3043,7 +3043,9 @@ describe("TreeView", function () { fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})); treeView.focus(); - spyOn(shell, 'moveItemToTrash').andReturn(false); + spyOn(shell, 'trashItem').andCallFake(() => { + return Promise.reject(false); + }); spyOn(atom, 'confirm').andCallFake((options, callback) => callback(0));