mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Remove event listeners with signal
in web/annotation_layer_builder.js and web/text_highlighter.js
This commit is contained in:
parent
2831caef13
commit
32b885c5ef
2 changed files with 26 additions and 28 deletions
|
@ -50,7 +50,7 @@ import { PresentationModeState } from "./ui_utils.js";
|
|||
class AnnotationLayerBuilder {
|
||||
#onAppend = null;
|
||||
|
||||
#onPresentationModeChanged = null;
|
||||
#eventAbortController = null;
|
||||
|
||||
/**
|
||||
* @param {AnnotationLayerBuilderOptions} options
|
||||
|
@ -155,13 +155,15 @@ class AnnotationLayerBuilder {
|
|||
if (this.linkService.isInPresentationMode) {
|
||||
this.#updatePresentationModeState(PresentationModeState.FULLSCREEN);
|
||||
}
|
||||
if (!this.#onPresentationModeChanged) {
|
||||
this.#onPresentationModeChanged = evt => {
|
||||
this.#updatePresentationModeState(evt.state);
|
||||
};
|
||||
if (!this.#eventAbortController) {
|
||||
this.#eventAbortController = new AbortController();
|
||||
|
||||
this._eventBus?._on(
|
||||
"presentationmodechanged",
|
||||
this.#onPresentationModeChanged
|
||||
evt => {
|
||||
this.#updatePresentationModeState(evt.state);
|
||||
},
|
||||
{ signal: this.#eventAbortController.signal }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -169,13 +171,8 @@ class AnnotationLayerBuilder {
|
|||
cancel() {
|
||||
this._cancelled = true;
|
||||
|
||||
if (this.#onPresentationModeChanged) {
|
||||
this._eventBus?._off(
|
||||
"presentationmodechanged",
|
||||
this.#onPresentationModeChanged
|
||||
);
|
||||
this.#onPresentationModeChanged = null;
|
||||
}
|
||||
this.#eventAbortController?.abort();
|
||||
this.#eventAbortController = null;
|
||||
}
|
||||
|
||||
hide() {
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
* either the text layer or XFA layer depending on the type of document.
|
||||
*/
|
||||
class TextHighlighter {
|
||||
#eventAbortController = null;
|
||||
|
||||
/**
|
||||
* @param {TextHighlighterOptions} options
|
||||
*/
|
||||
|
@ -37,7 +39,6 @@ class TextHighlighter {
|
|||
this.matches = [];
|
||||
this.eventBus = eventBus;
|
||||
this.pageIdx = pageIndex;
|
||||
this._onUpdateTextLayerMatches = null;
|
||||
this.textDivs = null;
|
||||
this.textContentItemsStr = null;
|
||||
this.enabled = false;
|
||||
|
@ -69,15 +70,18 @@ class TextHighlighter {
|
|||
throw new Error("TextHighlighter is already enabled.");
|
||||
}
|
||||
this.enabled = true;
|
||||
if (!this._onUpdateTextLayerMatches) {
|
||||
this._onUpdateTextLayerMatches = evt => {
|
||||
if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
|
||||
this._updateMatches();
|
||||
}
|
||||
};
|
||||
|
||||
if (!this.#eventAbortController) {
|
||||
this.#eventAbortController = new AbortController();
|
||||
|
||||
this.eventBus._on(
|
||||
"updatetextlayermatches",
|
||||
this._onUpdateTextLayerMatches
|
||||
evt => {
|
||||
if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
|
||||
this._updateMatches();
|
||||
}
|
||||
},
|
||||
{ signal: this.#eventAbortController.signal }
|
||||
);
|
||||
}
|
||||
this._updateMatches();
|
||||
|
@ -88,13 +92,10 @@ class TextHighlighter {
|
|||
return;
|
||||
}
|
||||
this.enabled = false;
|
||||
if (this._onUpdateTextLayerMatches) {
|
||||
this.eventBus._off(
|
||||
"updatetextlayermatches",
|
||||
this._onUpdateTextLayerMatches
|
||||
);
|
||||
this._onUpdateTextLayerMatches = null;
|
||||
}
|
||||
|
||||
this.#eventAbortController?.abort();
|
||||
this.#eventAbortController = null;
|
||||
|
||||
this._updateMatches(/* reset = */ true);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue