Skip to content

Commit 1ed88e7

Browse files
committed
Pause translation when appending the textLayer and structTreeLayer to the page
Note that we must append the textLayer to the DOM *before* enabling the `highlighter` and `accessibilityManager`, to avoid breaking e.g. a pending searching operation. The least invasive solution, that I was able to come up with, is to introduce a new `TextLayerBuilder` callback-function for this purpose.
1 parent 3478112 commit 1ed88e7

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

web/pdf_page_view.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,10 @@ class PDFPageView {
436436
: null);
437437
const treeDom = this.structTreeLayer?.render(tree);
438438
if (treeDom) {
439+
// Pause translation when inserting the structTree in the DOM.
440+
this.l10n.pause();
439441
this.canvas?.append(treeDom);
442+
this.l10n.resume();
440443
}
441444
this.structTreeLayer?.show();
442445
}
@@ -863,7 +866,12 @@ class PDFPageView {
863866
enablePermissions:
864867
this.#textLayerMode === TextLayerMode.ENABLE_PERMISSIONS,
865868
});
866-
div.append(this.textLayer.div);
869+
this.textLayer.onAppend = textLayerDiv => {
870+
// Pause translation when inserting the textLayer in the DOM.
871+
this.l10n.pause();
872+
this.div.append(textLayerDiv);
873+
this.l10n.resume();
874+
};
867875
}
868876

869877
if (

web/text_layer_builder.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@ class TextLayerBuilder {
6262
this.isOffscreenCanvasSupported = isOffscreenCanvasSupported;
6363
this.#enablePermissions = enablePermissions === true;
6464

65+
/**
66+
* Callback used to attach the textLayer to the DOM.
67+
* @type {function}
68+
*/
69+
this.onAppend = null;
70+
6571
this.div = document.createElement("div");
6672
this.div.className = "textLayer";
67-
this.hide();
6873
}
6974

7075
#finishRendering() {
@@ -131,12 +136,15 @@ class TextLayerBuilder {
131136
this.#finishRendering();
132137
this.#scale = scale;
133138
this.#rotation = rotation;
134-
this.show();
139+
// Ensure that the textLayer is appended to the DOM *before* handling
140+
// e.g. a pending search operation.
141+
this.onAppend(this.div);
142+
this.highlighter?.enable();
135143
this.accessibilityManager?.enable();
136144
}
137145

138146
hide() {
139-
if (!this.div.hidden) {
147+
if (!this.div.hidden && this.renderingDone) {
140148
// We turn off the highlighter in order to avoid to scroll into view an
141149
// element of the text layer which could be hidden.
142150
this.highlighter?.disable();

0 commit comments

Comments
 (0)