From 2de6fd8e70b271ab85cc4e0af5b5aeee5b128691 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 25 Apr 2023 21:28:20 +0200 Subject: [PATCH] Prevent incomplete copy-all behaviour while text-extraction is running (PR 16286 follow-up) Currently we only prevent triggering the actual text-extraction multiple times in "parallel", when using the "copy all text" feature, however the "copy"-event itself is not prevented. The result is that if the user selects all text in a long PDF document and then uses the copy-shortcut multiple times in quick succession, we'll actually populate the clipboard with "incomplete" contents (via a `TextLayerBuilder` copy-listener) until all text-extraction finishes. --- web/pdf_viewer.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index a55504479..ed7117ca8 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -691,19 +691,19 @@ class PDFViewer { // including this element so having it in the selection means that all // has been selected. - if (textLayerMode === TextLayerMode.ENABLE_PERMISSIONS) { + if ( + this.#getAllTextInProgress || + textLayerMode === TextLayerMode.ENABLE_PERMISSIONS + ) { event.preventDefault(); event.stopPropagation(); return; } + this.#getAllTextInProgress = true; + // TODO: if all the pages are rendered we don't need to wait for // getAllText and we could just get text from the Selection object. - if (this.#getAllTextInProgress) { - return; - } - this.#getAllTextInProgress = true; - // Select all the document. const savedCursor = this.container.style.cursor; this.container.style.cursor = "wait";