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.
This commit is contained in:
Jonas Jenwald 2023-04-25 21:28:20 +02:00
parent 495819fbc6
commit 2de6fd8e70

View File

@ -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";