diff --git a/src/display/editor/annotation_editor_layer.js b/src/display/editor/annotation_editor_layer.js index e6610febd814c..6ca2a79ec1d63 100644 --- a/src/display/editor/annotation_editor_layer.js +++ b/src/display/editor/annotation_editor_layer.js @@ -76,6 +76,8 @@ class AnnotationEditorLayer { #drawingAC = null; + #focusedElement = null; + #textLayer = null; #textSelectionAC = null; @@ -811,6 +813,7 @@ class AnnotationEditorLayer { "blur", ({ relatedTarget }) => { if (relatedTarget && !this.div.contains(relatedTarget)) { + this.#focusedElement = null; this.commitOrRemove(); } }, @@ -819,6 +822,22 @@ class AnnotationEditorLayer { this.#currentEditorType.startDrawing(this, this.#uiManager, false, event); } + pause(on) { + if (on) { + const { activeElement } = document; + if (this.div.contains(activeElement)) { + this.#focusedElement = activeElement; + } + return; + } + if (this.#focusedElement) { + setTimeout(() => { + this.#focusedElement?.focus(); + this.#focusedElement = null; + }, 0); + } + } + endDrawingSession(isAborted = false) { if (!this.#drawingAC) { return null; @@ -826,6 +845,7 @@ class AnnotationEditorLayer { this.#uiManager.setCurrentDrawingSession(null); this.#drawingAC.abort(); this.#drawingAC = null; + this.#focusedElement = null; return this.#currentEditorType.endDrawing(isAborted); } diff --git a/web/annotation_editor_layer_builder.js b/web/annotation_editor_layer_builder.js index 46082c163f838..f6240f2c47720 100644 --- a/web/annotation_editor_layer_builder.js +++ b/web/annotation_editor_layer_builder.js @@ -140,6 +140,7 @@ class AnnotationEditorLayerBuilder { if (!this.div) { return; } + this.annotationEditorLayer.pause(/* on */ true); this.div.hidden = true; } @@ -148,6 +149,7 @@ class AnnotationEditorLayerBuilder { return; } this.div.hidden = false; + this.annotationEditorLayer.pause(/* on */ false); } }