1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Improve how the wait-cursor is toggled when copying all text

- Use a CSS rule to display the wait-cursor during copying. Since copying may take a little while in long documents, there's a theoretical risk that something else could change the cursor in the meantime and just resetting to the saved-cursor could thus be incorrect.

 - Remove the `interruptCopyCondition` listener with an AbortController, since that's slightly shorter code.
This commit is contained in:
Jonas Jenwald 2024-06-14 10:00:53 +02:00
parent 47791a4c80
commit 97686c410c
2 changed files with 14 additions and 7 deletions

View file

@ -71,6 +71,10 @@
--hcm-highlight-filter: invert(100%);
}
&.copyAll {
cursor: wait;
}
.canvasWrapper {
overflow: hidden;
width: 100%;

View file

@ -740,12 +740,15 @@ class PDFViewer {
// getAllText and we could just get text from the Selection object.
// Select all the document.
const savedCursor = this.container.style.cursor;
this.container.style.cursor = "wait";
const { classList } = this.viewer;
classList.add("copyAll");
const interruptCopy = ev =>
(this.#interruptCopyCondition = ev.key === "Escape");
window.addEventListener("keydown", interruptCopy);
const ac = new AbortController();
window.addEventListener(
"keydown",
ev => (this.#interruptCopyCondition = ev.key === "Escape"),
{ signal: ac.signal }
);
this.getAllText()
.then(async text => {
@ -761,8 +764,8 @@ class PDFViewer {
.finally(() => {
this.#getAllTextInProgress = false;
this.#interruptCopyCondition = false;
window.removeEventListener("keydown", interruptCopy);
this.container.style.cursor = savedCursor;
ac.abort();
classList.remove("copyAll");
});
event.preventDefault();