From 949badde1c7df4c24cfc0417990f83ae9ff37999 Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Fri, 11 Aug 2023 18:45:22 +0300 Subject: [PATCH] Add missing Alt/Option + Number keyboard shortcuts zotero/zotero#3294 --- src/common/keyboard-manager.js | 37 +++++++++++++++++++++++++++++++++- src/common/reader.js | 10 +++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/common/keyboard-manager.js b/src/common/keyboard-manager.js index d84194f4..984263c2 100644 --- a/src/common/keyboard-manager.js +++ b/src/common/keyboard-manager.js @@ -23,7 +23,7 @@ export class KeyboardManager { } _handleKeyDown(event, view) { - let { key } = event; + let { key, code } = event; let ctrl = event.ctrlKey; let cmd = event.metaKey && isMac(); let mod = ctrl || cmd; @@ -110,6 +110,41 @@ export class KeyboardManager { event.preventDefault(); this._reader.zoomReset(); } + else if (alt && code === 'Digit1') { + this._reader.toggleTool('highlight'); + } + else if (alt && code === 'Digit2') { + this._reader.toggleTool('underline'); + } + else if (alt && code === 'Digit3') { + this._reader.toggleTool('note'); + } + else if (alt && this._reader._type === 'pdf' && code === 'Digit4') { + this._reader.toggleTool('text'); + } + else if (alt && this._reader._type === 'pdf' && code === 'Digit5') { + this._reader.toggleTool('image'); + } + else if (alt && this._reader._type === 'pdf' && code === 'Digit6') { + this._reader.toggleTool('ink'); + } + else if (alt && this._reader._type === 'pdf' && code === 'Digit7') { + this._reader.toggleTool('eraser'); + } + else if (alt + && ( + this._reader._type === 'pdf' && code === 'Digit8' + || ['epub', 'snapshot'].includes(this._reader._type) && code === 'Digit4' + ) && this._reader._state.tool.color) { + let idx = ANNOTATION_COLORS.findIndex(x => x[1] === this._reader._state.tool.color); + if (idx === ANNOTATION_COLORS.length - 1) { + idx = 0; + } + else { + idx++; + } + this._reader.setTool({ color: ANNOTATION_COLORS[idx][1] }) + } else if (['Delete', 'Backspace'].includes(key)) { if (isTextBox(event.target) && event.target.closest('#findbar') || event.target.closest('.label-overlay')) { return; diff --git a/src/common/reader.js b/src/common/reader.js index bfa7f3bd..ef333b63 100644 --- a/src/common/reader.js +++ b/src/common/reader.js @@ -495,6 +495,16 @@ class Reader { this._updateState({ tool }); } + toggleTool(type) { + let tool = this._state.tool; + if (tool.type === type) { + this._updateState({ tool: this._tools.pointer }); + } + else { + this._updateState({ tool: this._tools[type] }); + } + } + setFilter(filter) { this._annotationManager.setFilter(filter); }