From 593ceadc93c6bf46b90438f26aa249b593ef8b6d Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Wed, 10 Sep 2025 11:04:41 +0200 Subject: [PATCH] [Editor] Don't throw when switching to editing mode before an annotation editor layer is rendered It can happen with a pdf having a large text layer. Instead of waiting for the first rendered page to enable the buttons we wait for a rendered annotation editor layer. --- web/pdf_viewer.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index 424180447..c81186040 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -1072,6 +1072,20 @@ class PDFViewer { this._updateSpreadMode(); } + eventBus._on( + "annotationeditorlayerrendered", + evt => { + if (this.#annotationEditorUIManager) { + // Ensure that the Editor buttons, in the toolbar, are updated. + eventBus.dispatch("annotationeditormodechanged", { + source: this, + mode: this.#annotationEditorMode, + }); + } + }, + { once: true, signal } + ); + // Fetch all the pages since the viewport is needed before printing // starts to create the correct size canvas. Wait until one page is // rendered so we don't tie up too many resources early on. @@ -1090,14 +1104,6 @@ class PDFViewer { ); } - if (this.#annotationEditorUIManager) { - // Ensure that the Editor buttons, in the toolbar, are updated. - 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 (