From ae3742a6603c86142d7e3225fefe72e0e11f7f3a Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Tue, 9 Aug 2022 18:34:05 +0200 Subject: [PATCH] [Editing] Disable buttons until the first page is rendered --- web/base_viewer.js | 14 ++++++++------ web/toolbar.js | 8 +++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/web/base_viewer.js b/web/base_viewer.js index 6ce993b98566f..7fdb5c728a0be 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -727,12 +727,6 @@ class BaseViewer { if (isPureXfa) { console.warn("Warning: XFA-editing is not implemented."); } else if (isValidAnnotationEditorMode(mode)) { - // Ensure that the Editor buttons, in the toolbar, are updated. - this.eventBus.dispatch("annotationeditormodechanged", { - source: this, - mode, - }); - this.#annotationEditorUIManager = new AnnotationEditorUIManager( this.container, this.eventBus @@ -817,6 +811,14 @@ class BaseViewer { this._scriptingManager.setDocument(pdfDocument); // Enable scripting. } + if (this.#annotationEditorUIManager) { + // Ensure that the Editor buttons, in the toolbar, are updated. + this.eventBus.dispatch("annotationeditormodechanged", { + source: this, + mode: this.#annotationEditorMode, + }); + } + // In addition to 'disableAutoFetch' being set, also attempt to reduce // resource usage when loading *very* long/large documents. if ( diff --git a/web/toolbar.js b/web/toolbar.js index d0890a3e22e13..8abadbbaf5fdf 100644 --- a/web/toolbar.js +++ b/web/toolbar.js @@ -244,15 +244,17 @@ class Toolbar { } }; this.eventBus._on("annotationeditormodechanged", editorModeChanged); - - this.eventBus._on("toolbarreset", evt => { + const reset = evt => { if (evt.source === this) { editorModeChanged( { mode: AnnotationEditorType.NONE }, /* disableButtons = */ true ); } - }); + }; + + this.eventBus._on("toolbarreset", reset); + reset({ source: this }); } _updateUIState(resetNumPages = false) {