From fb63972042c9d32eaaca8476accdffb78773d8ff Mon Sep 17 00:00:00 2001 From: Ramon Mi Date: Thu, 5 Mar 2026 14:14:29 +0800 Subject: [PATCH 1/2] Add: select colors in text-selection popup with number keys fixes: zotero/zotero#4617 --- src/common/keyboard-manager.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/common/keyboard-manager.js b/src/common/keyboard-manager.js index 9616c52fb..e8343114d 100644 --- a/src/common/keyboard-manager.js +++ b/src/common/keyboard-manager.js @@ -48,6 +48,7 @@ export class KeyboardManager { let key = getKeyCombination(event); let code = getCodeCombination(event); + let textSelectionPopup = this._reader._state.primaryViewSelectionPopup || this._reader._state.secondaryViewSelectionPopup; let sidebarAnnotationFocused = document.activeElement.classList.contains('annotation'); let readAloudActive = this._reader._state.readAloudState.active; @@ -356,6 +357,35 @@ export class KeyboardManager { } if (!isTextBox(event.target)) { + if (textSelectionPopup) { + if (code === 'Alt-Digit1') { + event.preventDefault(); + event.stopPropagation(); + this._reader.setTextSelectionAnnotationMode('highlight'); + return; + } + else if (code === 'Alt-Digit2') { + event.preventDefault(); + event.stopPropagation(); + this._reader.setTextSelectionAnnotationMode('underline'); + return; + } + else if (code.startsWith('Digit')) { + let idx = parseInt(code.slice(5)) - 1; + if (ANNOTATION_COLORS[idx]) { + event.preventDefault(); + event.stopPropagation(); + this._reader._annotationManager.addAnnotation({ + ...textSelectionPopup.annotation, + type: this._reader._state.textSelectionAnnotationMode, + color: ANNOTATION_COLORS[idx][1] + }); + this._reader.setSelectedAnnotations([]); + return; + } + } + } + if (code === 'Alt-Digit1') { this._reader.toggleTool('highlight'); } From 6f026f8e12479ddee3a5b85f07c600a27e3b7d7e Mon Sep 17 00:00:00 2001 From: Ramon Mi Date: Thu, 5 Mar 2026 15:19:38 +0800 Subject: [PATCH 2/2] bind h/u as toggle shortcut --- src/common/keyboard-manager.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/keyboard-manager.js b/src/common/keyboard-manager.js index e8343114d..9b307a423 100644 --- a/src/common/keyboard-manager.js +++ b/src/common/keyboard-manager.js @@ -358,13 +358,13 @@ export class KeyboardManager { if (!isTextBox(event.target)) { if (textSelectionPopup) { - if (code === 'Alt-Digit1') { + if (key === 'h') { event.preventDefault(); event.stopPropagation(); this._reader.setTextSelectionAnnotationMode('highlight'); return; } - else if (code === 'Alt-Digit2') { + else if (key === 'u') { event.preventDefault(); event.stopPropagation(); this._reader.setTextSelectionAnnotationMode('underline'); @@ -426,7 +426,7 @@ export class KeyboardManager { this._reader.setTool({ color: ANNOTATION_COLORS[idx][1] }); } } - else if (this._reader._type === 'pdf' && key === 'h' && !this._reader._state.readAloudState.active) { + else if (this._reader._type === 'pdf' && key === 'h' && !textSelectionPopup && !readAloudActive) { this._reader.toggleHandTool(); } else if (this._reader._type === 'pdf' && key === 's') {