From 1f8e05bfd82187ccc7fc3edc73d51ee4e465f858 Mon Sep 17 00:00:00 2001 From: abaevbog Date: Thu, 29 May 2025 22:31:11 -0700 Subject: [PATCH] Fix new annotation changing the scroll position in itemTree (#5309) Extend scrollToRow in windowed-list.js to allow to scroll the specified row to the top of the window even if it is located below the current scroll window. With this, when scroll position is restored in itemTree, the same row remains at the top. Fixes: #5233 --- chrome/content/zotero/components/windowed-list.js | 8 +++++--- chrome/content/zotero/itemTree.jsx | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/components/windowed-list.js b/chrome/content/zotero/components/windowed-list.js index 9661735780..4a755a123a 100644 --- a/chrome/content/zotero/components/windowed-list.js +++ b/chrome/content/zotero/components/windowed-list.js @@ -202,9 +202,11 @@ module.exports = class { /** * Scroll the scrollbox to a specified item. No-op if already in view - * @param index + * @param {Integer} index + * @param {Boolean} forceScrollToTop If true, the row will be scrolled to the top of the scrollbox + * even if it is below the current scroll window. */ - scrollToRow(index) { + scrollToRow(index, forceScrollToTop = false) { const { scrollOffset } = this; const itemCount = this._getItemCount(); const height = this.getWindowHeight(); @@ -216,7 +218,7 @@ module.exports = class { this.scrollTo(startPosition); } else if (endPosition > scrollOffset + height) { - this.scrollTo(endPosition - height - 1); + this.scrollTo(forceScrollToTop ? startPosition : endPosition - height - 1); } } diff --git a/chrome/content/zotero/itemTree.jsx b/chrome/content/zotero/itemTree.jsx index 0607cb609a..4ae8181c61 100644 --- a/chrome/content/zotero/itemTree.jsx +++ b/chrome/content/zotero/itemTree.jsx @@ -3752,7 +3752,7 @@ var ItemTree = class ItemTree extends LibraryTree { if (row === false) { return; } - this._treebox.scrollToRow(Math.max(row - scrollPosition.offset, 0)); + this._treebox.scrollToRow(Math.max(row - scrollPosition.offset, 0), true); } /**