From e7800c22ddff9be4462900b1f6581676fc1ecb3f Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 4 Sep 2023 23:11:30 +0200 Subject: [PATCH] Support downloading FileAttachment annotations with the keyboard While reviewing PR 16898 it occurred to me that it's currently impossible to trigger downloading of FileAttachment annotations using the keyboard. Hence this patch adds `Ctrl + Enter` as the keyboard shortcut to download those, thus supplementing the existing double-clicking when using a mouse. --- src/display/annotation_layer.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 8a8ecb5af..cba633a0e 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -2745,7 +2745,7 @@ class FileAttachmentAnnotationElement extends AnnotationElement { render() { this.container.classList.add("fileAttachmentAnnotation"); - const { data } = this; + const { container, data } = this; let trigger; if (data.hasAppearance || data.fillAlpha === 0) { trigger = document.createElement("div"); @@ -2770,17 +2770,24 @@ class FileAttachmentAnnotationElement extends AnnotationElement { } } } - trigger.addEventListener("dblclick", this._download.bind(this)); + trigger.addEventListener("dblclick", this.#download.bind(this)); this.#trigger = trigger; + const { isMac } = FeatureTest.platform; + container.addEventListener("keydown", evt => { + if (evt.key === "Enter" && (isMac ? evt.metaKey : evt.ctrlKey)) { + this.#download(); + } + }); + if (!data.popupRef && this.hasPopupData) { this._createPopup(); } else { trigger.classList.add("popupTriggerArea"); } - this.container.append(trigger); - return this.container; + container.append(trigger); + return container; } getElementsToTriggerPopup() { @@ -2793,11 +2800,8 @@ class FileAttachmentAnnotationElement extends AnnotationElement { /** * Download the file attachment associated with this annotation. - * - * @private - * @memberof FileAttachmentAnnotationElement */ - _download() { + #download() { this.downloadManager?.openOrDownloadData( this.container, this.content,