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%); --hcm-highlight-filter: invert(100%);
} }
&.copyAll {
cursor: wait;
}
.canvasWrapper { .canvasWrapper {
overflow: hidden; overflow: hidden;
width: 100%; width: 100%;

View file

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