From 934545260180e5816cbf6e42d7b67e701fd7bdcb Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 9 May 2016 13:54:19 -0400 Subject: [PATCH] Don't restore items tree scroll position if selecting new items --- chrome/content/zotero/xpcom/itemTreeView.js | 7 ++++++- test/tests/itemTreeViewTest.js | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js index 960a622654..36827270a9 100644 --- a/chrome/content/zotero/xpcom/itemTreeView.js +++ b/chrome/content/zotero/xpcom/itemTreeView.js @@ -487,7 +487,12 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio var savedSelection = this.getSelectedItems(true); var previousFirstSelectedRow = this._rowMap[ids[0]]; - var scrollPosition = this._saveScrollPosition(); + + // If there's not at least one new item to be selected, get a scroll position to restore later + var scrollPosition = false; + if (action != 'add' || ids.every(id => extraData[id] && extraData[id].skipSelect)) { + scrollPosition = this._saveScrollPosition(); + } // Redraw the tree (for tag color and progress changes) if (action == 'redraw') { diff --git a/test/tests/itemTreeViewTest.js b/test/tests/itemTreeViewTest.js index 73e6726527..c36f6b5e24 100644 --- a/test/tests/itemTreeViewTest.js +++ b/test/tests/itemTreeViewTest.js @@ -260,7 +260,7 @@ describe("Zotero.ItemTreeView", function() { yield Zotero.Items.erase(items.map(item => item.id)); }) - it("should keep first visible item in view when other items are added or removed with skipSelect and nothing in view is selected", function* () { + 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'); yield waitForItemsLoad(win); itemsView = zp.itemsView; @@ -311,7 +311,7 @@ describe("Zotero.ItemTreeView", function() { assert.equal(itemsView.getRow(treebox.getFirstVisibleRow()).ref.id, firstVisibleItemID); }); - it("should keep first visible selected item in position when other items are added or removed with skipSelect", function* () { + it("should keep first visible selected item in position when other items are added with skipSelect", function* () { var collection = yield createDataObject('collection'); yield waitForItemsLoad(win); itemsView = zp.itemsView; @@ -367,7 +367,7 @@ describe("Zotero.ItemTreeView", function() { assert.equal(newOffset, offset); }); - it("shouldn't scroll items list if at top when other items are added or removed with skipSelect", function* () { + it("shouldn't scroll items list if at top when other items are added with skipSelect", function* () { var collection = yield createDataObject('collection'); yield waitForItemsLoad(win); itemsView = zp.itemsView;