Merge pull request #18842 from Snuffleupagus/annotationEditorMode-AbortSignal-any
Remove the `PDFViewer.annotationEditorMode` setter event listeners with `AbortSignal.any()`
This commit is contained in:
commit
ebbd019d7d
@ -227,7 +227,7 @@ class PDFViewer {
|
|||||||
|
|
||||||
#mlManager = null;
|
#mlManager = null;
|
||||||
|
|
||||||
#onPageRenderedCallback = null;
|
#switchAnnotationEditorModeAC = null;
|
||||||
|
|
||||||
#switchAnnotationEditorModeTimeoutId = null;
|
#switchAnnotationEditorModeTimeoutId = null;
|
||||||
|
|
||||||
@ -2280,10 +2280,9 @@ class PDFViewer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#cleanupSwitchAnnotationEditorMode() {
|
#cleanupSwitchAnnotationEditorMode() {
|
||||||
if (this.#onPageRenderedCallback) {
|
this.#switchAnnotationEditorModeAC?.abort();
|
||||||
this.eventBus._off("pagerendered", this.#onPageRenderedCallback);
|
this.#switchAnnotationEditorModeAC = null;
|
||||||
this.#onPageRenderedCallback = null;
|
|
||||||
}
|
|
||||||
if (this.#switchAnnotationEditorModeTimeoutId !== null) {
|
if (this.#switchAnnotationEditorModeTimeoutId !== null) {
|
||||||
clearTimeout(this.#switchAnnotationEditorModeTimeoutId);
|
clearTimeout(this.#switchAnnotationEditorModeTimeoutId);
|
||||||
this.#switchAnnotationEditorModeTimeoutId = null;
|
this.#switchAnnotationEditorModeTimeoutId = null;
|
||||||
@ -2353,14 +2352,25 @@ class PDFViewer {
|
|||||||
// We're editing so we must switch to editing mode when the rendering is
|
// We're editing so we must switch to editing mode when the rendering is
|
||||||
// done.
|
// done.
|
||||||
this.#cleanupSwitchAnnotationEditorMode();
|
this.#cleanupSwitchAnnotationEditorMode();
|
||||||
this.#onPageRenderedCallback = ({ pageNumber }) => {
|
this.#switchAnnotationEditorModeAC = new AbortController();
|
||||||
idsToRefresh.delete(pageNumber);
|
const signal = AbortSignal.any([
|
||||||
if (idsToRefresh.size === 0) {
|
this.#eventAbortController.signal,
|
||||||
this.#switchAnnotationEditorModeTimeoutId = setTimeout(updater, 0);
|
this.#switchAnnotationEditorModeAC.signal,
|
||||||
}
|
]);
|
||||||
};
|
|
||||||
const { signal } = this.#eventAbortController;
|
eventBus._on(
|
||||||
eventBus._on("pagerendered", this.#onPageRenderedCallback, { signal });
|
"pagerendered",
|
||||||
|
({ pageNumber }) => {
|
||||||
|
idsToRefresh.delete(pageNumber);
|
||||||
|
if (idsToRefresh.size === 0) {
|
||||||
|
this.#switchAnnotationEditorModeTimeoutId = setTimeout(
|
||||||
|
updater,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ signal }
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user