From 227b6354de5908d4d36d86b7a7c60b564dedda47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Tue, 22 Mar 2022 13:50:15 +0200 Subject: [PATCH] Item Tree: Reset scrollbar to top on collection change --- chrome/content/zotero/components/windowed-list.js | 2 +- chrome/content/zotero/itemTree.jsx | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/components/windowed-list.js b/chrome/content/zotero/components/windowed-list.js index 08cae8f707..28ed3d78c1 100644 --- a/chrome/content/zotero/components/windowed-list.js +++ b/chrome/content/zotero/components/windowed-list.js @@ -164,7 +164,7 @@ module.exports = class { * @param scrollOffset {Integer} offset for the top of the tree */ scrollTo(scrollOffset) { - const maxOffset = this.itemHeight * this._getItemCount() - this.getWindowHeight(); + const maxOffset = Math.max(0, this.itemHeight * this._getItemCount() - this.getWindowHeight()); scrollOffset = Math.min(Math.max(0, scrollOffset), maxOffset); this.scrollOffset = scrollOffset; this.targetElement.scrollTop = scrollOffset; diff --git a/chrome/content/zotero/itemTree.jsx b/chrome/content/zotero/itemTree.jsx index 5c53a1898b..2692eab432 100644 --- a/chrome/content/zotero/itemTree.jsx +++ b/chrome/content/zotero/itemTree.jsx @@ -1021,6 +1021,8 @@ var ItemTree = class ItemTree extends LibraryTree { } this.forceUpdate(() => { this.selection.selectEventsSuppressed = false; + // Reset scrollbar to top + this._treebox && this._treebox.scrollTo(0); this._updateIntroText(); this._itemTreeLoadingDeferred.resolve(); });