Skip to content

Commit d174891

Browse files
Snuffleupaguspull[bot]
authored andcommitted
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.
1 parent f57683d commit d174891

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

web/pdf_viewer.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -691,19 +691,19 @@ class PDFViewer {
691691
// including this element so having it in the selection means that all
692692
// has been selected.
693693

694-
if (textLayerMode === TextLayerMode.ENABLE_PERMISSIONS) {
694+
if (
695+
this.#getAllTextInProgress ||
696+
textLayerMode === TextLayerMode.ENABLE_PERMISSIONS
697+
) {
695698
event.preventDefault();
696699
event.stopPropagation();
697700
return;
698701
}
702+
this.#getAllTextInProgress = true;
703+
699704
// TODO: if all the pages are rendered we don't need to wait for
700705
// getAllText and we could just get text from the Selection object.
701706

702-
if (this.#getAllTextInProgress) {
703-
return;
704-
}
705-
this.#getAllTextInProgress = true;
706-
707707
// Select all the document.
708708
const savedCursor = this.container.style.cursor;
709709
this.container.style.cursor = "wait";

0 commit comments

Comments
 (0)