mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
Remove the PDFViewer.annotationEditorMode
setter event listeners with AbortSignal.any()
This commit is contained in:
parent
4fb3adfc0f
commit
b7ae92c11c
1 changed files with 23 additions and 13 deletions
|
@ -227,7 +227,7 @@ class PDFViewer {
|
|||
|
||||
#mlManager = null;
|
||||
|
||||
#onPageRenderedCallback = null;
|
||||
#switchAnnotationEditorModeAC = null;
|
||||
|
||||
#switchAnnotationEditorModeTimeoutId = null;
|
||||
|
||||
|
@ -2280,10 +2280,9 @@ class PDFViewer {
|
|||
}
|
||||
|
||||
#cleanupSwitchAnnotationEditorMode() {
|
||||
if (this.#onPageRenderedCallback) {
|
||||
this.eventBus._off("pagerendered", this.#onPageRenderedCallback);
|
||||
this.#onPageRenderedCallback = null;
|
||||
}
|
||||
this.#switchAnnotationEditorModeAC?.abort();
|
||||
this.#switchAnnotationEditorModeAC = null;
|
||||
|
||||
if (this.#switchAnnotationEditorModeTimeoutId !== null) {
|
||||
clearTimeout(this.#switchAnnotationEditorModeTimeoutId);
|
||||
this.#switchAnnotationEditorModeTimeoutId = null;
|
||||
|
@ -2353,14 +2352,25 @@ class PDFViewer {
|
|||
// We're editing so we must switch to editing mode when the rendering is
|
||||
// done.
|
||||
this.#cleanupSwitchAnnotationEditorMode();
|
||||
this.#onPageRenderedCallback = ({ pageNumber }) => {
|
||||
idsToRefresh.delete(pageNumber);
|
||||
if (idsToRefresh.size === 0) {
|
||||
this.#switchAnnotationEditorModeTimeoutId = setTimeout(updater, 0);
|
||||
}
|
||||
};
|
||||
const { signal } = this.#eventAbortController;
|
||||
eventBus._on("pagerendered", this.#onPageRenderedCallback, { signal });
|
||||
this.#switchAnnotationEditorModeAC = new AbortController();
|
||||
const signal = AbortSignal.any([
|
||||
this.#eventAbortController.signal,
|
||||
this.#switchAnnotationEditorModeAC.signal,
|
||||
]);
|
||||
|
||||
eventBus._on(
|
||||
"pagerendered",
|
||||
({ pageNumber }) => {
|
||||
idsToRefresh.delete(pageNumber);
|
||||
if (idsToRefresh.size === 0) {
|
||||
this.#switchAnnotationEditorModeTimeoutId = setTimeout(
|
||||
updater,
|
||||
0
|
||||
);
|
||||
}
|
||||
},
|
||||
{ signal }
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue