diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js index 7a48da92c..b6ee22aec 100644 --- a/chrome/content/zotero/xpcom/itemTreeView.js +++ b/chrome/content/zotero/xpcom/itemTreeView.js @@ -901,9 +901,10 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio this.rememberSelection(savedSelection); } } - // On removal of a row, select item at previous position + // On removal of a selected row, select item at previous position else if (savedSelection.length) { - if (action == 'remove' || action == 'trash' || action == 'delete') { + if ((action == 'remove' || action == 'trash' || action == 'delete') + && savedSelection.some(id => this.getRowIndexByID(id) === false)) { // In duplicates view, select the next set on delete if (collectionTreeRow.isDuplicates()) { if (this._rows[previousFirstSelectedRow]) { diff --git a/test/tests/itemTreeViewTest.js b/test/tests/itemTreeViewTest.js index eb2d6b9e6..2a30097ae 100644 --- a/test/tests/itemTreeViewTest.js +++ b/test/tests/itemTreeViewTest.js @@ -269,7 +269,17 @@ describe("Zotero.ItemTreeView", function() { assert.equal(itemsView.selection.currentIndex, 2); yield Zotero.Items.erase(items.map(item => item.id)); - }) + }); + + it("shouldn't select sibling on attachment erase if attachment wasn't selected", function* () { + var item = yield createDataObject('item'); + var att1 = yield importFileAttachment('test.png', { title: 'A', parentItemID: item.id }); + var att2 = yield importFileAttachment('test.png', { title: 'B', parentItemID: item.id }); + yield zp.itemsView.selectItem(att2.id); // expand + yield zp.itemsView.selectItem(item.id); + yield att1.eraseTx(); + assert.sameMembers(zp.itemsView.getSelectedItems(true), [item.id]); + }); it("should keep first visible item in view when other items are added with skipSelect and nothing in view is selected", function* () { var collection = yield createDataObject('collection');