diff --git a/web/l10n_utils.js b/web/l10n_utils.js index e9998da975853..057695a6ce2d5 100644 --- a/web/l10n_utils.js +++ b/web/l10n_utils.js @@ -76,11 +76,11 @@ const NullL10n = { }, pause() { - ConstL10n.instance.pause(); + return ConstL10n.instance.pause(); }, resume() { - ConstL10n.instance.resume(); + return ConstL10n.instance.resume(); }, }; diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 0c946e1c057ff..d59d14fa97851 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -359,12 +359,23 @@ class PDFPageView { try { const result = await this.xfaLayer.render(this.viewport, "display"); if (result?.textDivs && this._textHighlighter) { + // Given that the following method fetches the text asynchronously we + // can invoke it *before* appending the xfaLayer to the DOM (below), + // since a pending search-highlight/scroll operation thus won't run + // until after the xfaLayer is available in the viewer. this.#buildXfaTextContentItems(result.textDivs); } } catch (ex) { console.error(`#renderXfaLayer: "${ex}".`); error = ex; } finally { + if (this.xfaLayer?.div) { + // Pause translation when inserting the xfaLayer in the DOM. + this.l10n.pause(); + this.div.append(this.xfaLayer.div); + this.l10n.resume(); + } + this.eventBus.dispatch("xfalayerrendered", { source: this, pageNumber: this.id, @@ -1020,9 +1031,6 @@ class PDFPageView { annotationStorage, linkService, }); - } else if (this.xfaLayer.div) { - // The xfa layer needs to stay on top. - div.append(this.xfaLayer.div); } this.#renderXfaLayer(); } diff --git a/web/xfa_layer_builder.js b/web/xfa_layer_builder.js index b3f94afbab1af..ad6f9175ba356 100644 --- a/web/xfa_layer_builder.js +++ b/web/xfa_layer_builder.js @@ -98,7 +98,6 @@ class XfaLayerBuilder { } // Create an xfa layer div and render the form this.div = document.createElement("div"); - this.pageDiv.append(this.div); parameters.div = this.div; return XfaLayer.render(parameters);