From 1eacc8bbdfd1314159daa1299f387c99e4be6edf Mon Sep 17 00:00:00 2001 From: abaevbog Date: Fri, 9 May 2025 21:29:44 -0700 Subject: [PATCH] Citation dialog: updated Enter handling in panels (#5281) Unhandled Enter keypress from inside of a panel will now close it. Enter on "Omit Author" checkbox or on the inactive locator label dropdown will close the item details popup. Enter on "Keep sources sorted" checkbox of settings popup will close it for consistency. Fixes: #5277 --- .../content/zotero/integration/citationDialog.xhtml | 4 ++-- .../integration/citationDialog/keyboardHandler.mjs | 11 +++++++++-- .../integration/citationDialog/popupHandler.mjs | 9 --------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/chrome/content/zotero/integration/citationDialog.xhtml b/chrome/content/zotero/integration/citationDialog.xhtml index 1900a29f51..58fee6d474 100644 --- a/chrome/content/zotero/integration/citationDialog.xhtml +++ b/chrome/content/zotero/integration/citationDialog.xhtml @@ -122,7 +122,7 @@
- +
@@ -138,7 +138,7 @@ diff --git a/chrome/content/zotero/integration/citationDialog/keyboardHandler.mjs b/chrome/content/zotero/integration/citationDialog/keyboardHandler.mjs index 6f37569880..c14f2ca8b7 100644 --- a/chrome/content/zotero/integration/citationDialog/keyboardHandler.mjs +++ b/chrome/content/zotero/integration/citationDialog/keyboardHandler.mjs @@ -86,12 +86,19 @@ export class CitationDialogKeyboardHandler { _handleTopLevelKeydown(event) { let handled = false; let tgt = event.target; - let isKeyboardClickable = tgt.classList.contains("keyboard-clickable") || tgt.tagName.includes("button"); - // Space/Enter will click on a button or keyboard-clickable components + // Space/Enter will click on keyboard-clickable components. + // On macOS, focused buttons are only clickable with Space (not Enter), + // and on Windows they are clickable with both. + let isKeyboardClickable = tgt.classList.contains("keyboard-clickable") || (Zotero.isWin && tgt.localName == "button"); if (["Enter", " "].includes(event.key) && isKeyboardClickable) { tgt.click(); handled = true; } + // Unhandled Enter in a panel will close it + else if (event.key == "Enter" && tgt.closest("panel")) { + handled = true; + tgt.closest("panel").hidePopup(); + } // Unhandled Enter will accept the existing dialog's state else if (event.key == "Enter" && !tgt.closest("panel")) { handled = true; diff --git a/chrome/content/zotero/integration/citationDialog/popupHandler.mjs b/chrome/content/zotero/integration/citationDialog/popupHandler.mjs index fd065409f1..dbf43f279e 100644 --- a/chrome/content/zotero/integration/citationDialog/popupHandler.mjs +++ b/chrome/content/zotero/integration/citationDialog/popupHandler.mjs @@ -84,8 +84,6 @@ export class CitationDialogPopupsHandler { if (this._getNode("#itemDetails").state !== "open") return; this.captureItemDetailsKeyDown(event); }, true); - // Handle remaining keypress events with a usual bubbling listener - this._getNode("#itemDetails").addEventListener("keypress", this.handleItemDetailsKeypress.bind(this)); } openItemDetails(dialogReferenceID, item, citationItem, itemDescription) { @@ -182,13 +180,6 @@ export class CitationDialogPopupsHandler { } } - handleItemDetailsKeypress(event) { - // Enter on a an input will save changes and hide the popup - if (event.key == "Enter" && ["input"].includes(event.target.tagName) && !event.target.getAttribute("type")) { - this._getNode("#itemDetails").hidePopup(); - } - } - // Update item details and notify citation dialog about changes handleItemDetailsChange() { this.citationItem.label = this._getNode("#locator").value ? this._getNode("#label").value : null;