From 5bf460771ce38210762fc29eb863d55fecb55ccc Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Thu, 8 May 2025 22:49:21 +0200 Subject: [PATCH 1/4] Improve attachment row annotation button click behavior fix: #5249 --- chrome/content/zotero/elements/attachmentRow.js | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/chrome/content/zotero/elements/attachmentRow.js b/chrome/content/zotero/elements/attachmentRow.js index 72fc1f705b..8f128f208e 100644 --- a/chrome/content/zotero/elements/attachmentRow.js +++ b/chrome/content/zotero/elements/attachmentRow.js @@ -107,20 +107,8 @@ import { getCSSItemTypeIcon } from 'components/icons'; }; _handleAnnotationClick = () => { - // TODO: jump to annotations pane - let pane; - if (ZoteroContextPane) { - pane = ZoteroContextPane.sidenav?.container.querySelector(`:scope > [data-pane="attachment-annotations"]`); - } - if (pane) { - pane._section.open = true; - } - let win = Zotero.getMainWindow(); - if (win) { - win.ZoteroPane.selectItem(this._attachment.id); - win.Zotero_Tabs.select('zotero-pane'); - win.focus(); - } + Zotero_Tabs.select('zotero-pane'); + ZoteroPane.selectItems(this._attachment.getAnnotations().map(a => a.id)); }; _handleRemove = async () => { From 0ba77057544607de3f9dc046d2c31059d0523b14 Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Thu, 8 May 2025 23:27:53 +0200 Subject: [PATCH 2/4] Fix tests --- test/tests/itemPaneTest.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tests/itemPaneTest.js b/test/tests/itemPaneTest.js index 80ea4f5b01..1631b8b3c1 100644 --- a/test/tests/itemPaneTest.js +++ b/test/tests/itemPaneTest.js @@ -1157,8 +1157,8 @@ describe("Item pane", function () { let attachmentRow = attachmentsBox.querySelector(`attachment-row[attachment-id="${attachment.id}"]`); attachmentRow._annotationButton.click(); await Zotero.Promise.delay(100); - // Should select attachment - assert.equal(ZoteroPane.getSelectedItems(true)[0], attachment.id); + // Should select annotations + assert.deepEqual(ZoteroPane.getSelectedItems(true), [_annotation.id]); }); it("should open attachment on double-clicking attachments pane preview", async function () { From 6757df36b023555e59025b86e1d51affa909c671 Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Fri, 13 Jun 2025 11:00:59 +0200 Subject: [PATCH 3/4] Select attachment item and scroll to annotations section --- .../content/zotero/elements/attachmentRow.js | 17 +++++++++--- chrome/content/zotero/elements/itemDetails.js | 26 +++++++++++++++---- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/chrome/content/zotero/elements/attachmentRow.js b/chrome/content/zotero/elements/attachmentRow.js index 8f128f208e..d5880ef01b 100644 --- a/chrome/content/zotero/elements/attachmentRow.js +++ b/chrome/content/zotero/elements/attachmentRow.js @@ -106,9 +106,20 @@ import { getCSSItemTypeIcon } from 'components/icons'; Zotero.Utilities.Internal.onDragItems(event, [this._attachment.id]); }; - _handleAnnotationClick = () => { - Zotero_Tabs.select('zotero-pane'); - ZoteroPane.selectItems(this._attachment.getAnnotations().map(a => a.id)); + _handleAnnotationClick = async () => { + let paneID = "attachment-annotations"; + let win = Zotero.getMainWindow(); + if (win) { + win.Zotero_Tabs.select('zotero-pane'); + let itemDetails = win.ZoteroContextPane.sidenav?.container; + let pane = itemDetails?.getPane(paneID); + if (pane) { + pane._section.open = true; + await itemDetails?.scrollToPane(paneID, 'instant', { pendingScroll: true }); + } + await win.ZoteroPane.selectItem(this._attachment.id); + win.focus(); + } }; _handleRemove = async () => { diff --git a/chrome/content/zotero/elements/itemDetails.js b/chrome/content/zotero/elements/itemDetails.js index 71b7365a03..17bf62e1a2 100644 --- a/chrome/content/zotero/elements/itemDetails.js +++ b/chrome/content/zotero/elements/itemDetails.js @@ -541,19 +541,35 @@ } } - async scrollToPane(paneID, behavior = 'smooth') { - let panes = this.getEnabledPanes(); + /** + * Scroll to a specific pane section. + * @param {string} paneID - ID of the section to scroll to + * @param {'smooth' | 'instant'} behavior - 'smooth' for smooth scrolling, 'instant' for instant scroll + * @param {object} [options] + * @param {boolean} [options.pendingScroll = false] - If true, the pane will be scrolled to when `render` is called. + * @returns {Promise} - Returns true if the pane was/will be scrolled to, false otherwise. + */ + async scrollToPane(paneID, behavior = 'smooth', options = {}) { + let { pendingScroll = false } = options; + let panes; + // For pending scroll, hidden sections are also considered + if (pendingScroll) { + panes = this.getPanes(); + } + else { + panes = this.getEnabledPanes(); + } let paneIndex = panes.findIndex(elem => elem.dataset.pane == paneID); let pane = panes[paneIndex]; - if (!pane) return null; + if (!pane) return false; let scrollPromise; // If the itemPane is collapsed, just remember which pane needs to be scrolled to // when itemPane is expanded. - if (this._collapsed) { + if (this._collapsed || pendingScroll) { this._lastScrollPaneID = paneID; - return null; + return true; } // Temporarily disable intersection observer to prevent unwanted rendering From fbd41e28725b7b9aa4381434b7c0ea8516c541cf Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Fri, 13 Jun 2025 11:01:11 +0200 Subject: [PATCH 4/4] Revert "Fix tests" This reverts commit 0ba77057544607de3f9dc046d2c31059d0523b14. --- test/tests/itemPaneTest.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tests/itemPaneTest.js b/test/tests/itemPaneTest.js index 1631b8b3c1..80ea4f5b01 100644 --- a/test/tests/itemPaneTest.js +++ b/test/tests/itemPaneTest.js @@ -1157,8 +1157,8 @@ describe("Item pane", function () { let attachmentRow = attachmentsBox.querySelector(`attachment-row[attachment-id="${attachment.id}"]`); attachmentRow._annotationButton.click(); await Zotero.Promise.delay(100); - // Should select annotations - assert.deepEqual(ZoteroPane.getSelectedItems(true), [_annotation.id]); + // Should select attachment + assert.equal(ZoteroPane.getSelectedItems(true)[0], attachment.id); }); it("should open attachment on double-clicking attachments pane preview", async function () {