From 82735537bf62cbbf70815e5e9433f2cb1a93994e Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 13 Aug 2024 14:51:16 +0200 Subject: [PATCH 1/2] Use the local `eventBus` in the `AnnotationEditorUIManager` constructor This shortens the code ever so slightly, which cannot hurt. --- src/display/editor/tools.js | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/display/editor/tools.js b/src/display/editor/tools.js index 871ab9cef9d3e..51bce8d877639 100644 --- a/src/display/editor/tools.js +++ b/src/display/editor/tools.js @@ -776,21 +776,13 @@ class AnnotationEditorUIManager { this.#viewer = viewer; this.#altTextManager = altTextManager; this._eventBus = eventBus; - this._eventBus._on("editingaction", this.onEditingAction.bind(this), { - signal, - }); - this._eventBus._on("pagechanging", this.onPageChanging.bind(this), { - signal, - }); - this._eventBus._on("scalechanging", this.onScaleChanging.bind(this), { - signal, - }); - this._eventBus._on("rotationchanging", this.onRotationChanging.bind(this), { - signal, - }); - this._eventBus._on("setpreference", this.onSetPreference.bind(this), { + eventBus._on("editingaction", this.onEditingAction.bind(this), { signal }); + eventBus._on("pagechanging", this.onPageChanging.bind(this), { signal }); + eventBus._on("scalechanging", this.onScaleChanging.bind(this), { signal }); + eventBus._on("rotationchanging", this.onRotationChanging.bind(this), { signal, }); + eventBus._on("setpreference", this.onSetPreference.bind(this), { signal }); this.#addSelectionListener(); this.#addDragAndDropListeners(); this.#addKeyboardManager(); From 9e0c6ef4763729f3509ecc1d9ddea28ca7965db8 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 13 Aug 2024 15:23:23 +0200 Subject: [PATCH 2/2] Handle the "switchannotationeditorparams" event in the editor-code (issue 18196) The problem seems to be caused by the browser trying to "restore" editing input-elements, in the various toolbars, to their previous values when the tab is re-opened. Hence the simplest solution appears to be to move the event handling into the editor-code, which is also less code overall, since the listener thus won't be registered early enough for the problem to appear. --- src/display/editor/tools.js | 5 +++++ web/app.js | 5 ----- web/pdf_viewer.js | 8 -------- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/display/editor/tools.js b/src/display/editor/tools.js index 51bce8d877639..e17b1bfb97775 100644 --- a/src/display/editor/tools.js +++ b/src/display/editor/tools.js @@ -783,6 +783,11 @@ class AnnotationEditorUIManager { signal, }); eventBus._on("setpreference", this.onSetPreference.bind(this), { signal }); + eventBus._on( + "switchannotationeditorparams", + evt => this.updateParams(evt.type, evt.value), + { signal } + ); this.#addSelectionListener(); this.#addDragAndDropListeners(); this.#addKeyboardManager(); diff --git a/web/app.js b/web/app.js index 6ae653135ee35..2cf98b917563a 100644 --- a/web/app.js +++ b/web/app.js @@ -1939,11 +1939,6 @@ const PDFViewerApplication = { evt => (pdfViewer.annotationEditorMode = evt), { signal } ); - eventBus._on( - "switchannotationeditorparams", - evt => (pdfViewer.annotationEditorParams = evt), - { signal } - ); eventBus._on("print", this.triggerPrinting.bind(this), { signal }); eventBus._on("download", this.downloadOrSave.bind(this), { signal }); eventBus._on("firstpage", () => (this.page = 1), { signal }); diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index c53678ba365d3..8ef7d25a9a1db 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -2363,14 +2363,6 @@ class PDFViewer { updater(); } - // eslint-disable-next-line accessor-pairs - set annotationEditorParams({ type, value }) { - if (!this.#annotationEditorUIManager) { - throw new Error(`The AnnotationEditor is not enabled.`); - } - this.#annotationEditorUIManager.updateParams(type, value); - } - refresh(noUpdate = false, updateArgs = Object.create(null)) { if (!this.pdfDocument) { return;