Skip to content

Commit

Permalink
Fix failing tree-view specs
Browse files Browse the repository at this point in the history
  • Loading branch information
savetheclocktower committed Dec 4, 2024
1 parent 47bf2a6 commit dbbc15f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 13 additions & 3 deletions packages/tree-view/lib/tree-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')) {
Expand Down
4 changes: 3 additions & 1 deletion packages/tree-view/spec/tree-view-package-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit dbbc15f

Please sign in to comment.