diff --git a/src/display/editor/tools.js b/src/display/editor/tools.js index 71983b850..bca94e7e6 100644 --- a/src/display/editor/tools.js +++ b/src/display/editor/tools.js @@ -721,7 +721,7 @@ class AnnotationEditorUIManager { } destroy() { - this.removeKeyboardManager(); + this.#removeKeyboardManager(); this.#removeFocusManager(); this.#eventBus._off("editingaction", this.#boundOnEditingAction); this.#eventBus._off("pagechanging", this.#boundOnPageChanging); @@ -875,13 +875,13 @@ class AnnotationEditorUIManager { lastActiveElement.focus(); } - addKeyboardManager() { + #addKeyboardManager() { // The keyboard events are caught at the container level in order to be able // to execute some callbacks even if the current page doesn't have focus. window.addEventListener("keydown", this.#boundKeydown, { capture: true }); } - removeKeyboardManager() { + #removeKeyboardManager() { window.removeEventListener("keydown", this.#boundKeydown, { capture: true, }); @@ -899,6 +899,16 @@ class AnnotationEditorUIManager { document.removeEventListener("paste", this.#boundPaste); } + addEditListeners() { + this.#addKeyboardManager(); + this.#addCopyPasteListeners(); + } + + removeEditListeners() { + this.#removeKeyboardManager(); + this.#removeCopyPasteListeners(); + } + /** * Copy callback. * @param {ClipboardEvent} event @@ -1054,7 +1064,7 @@ class AnnotationEditorUIManager { setEditingState(isEditing) { if (isEditing) { this.#addFocusManager(); - this.addKeyboardManager(); + this.#addKeyboardManager(); this.#addCopyPasteListeners(); this.#dispatchUpdateStates({ isEditing: this.#mode !== AnnotationEditorType.NONE, @@ -1065,7 +1075,7 @@ class AnnotationEditorUIManager { }); } else { this.#removeFocusManager(); - this.removeKeyboardManager(); + this.#removeKeyboardManager(); this.#removeCopyPasteListeners(); this.#dispatchUpdateStates({ isEditing: false, diff --git a/web/alt_text_manager.js b/web/alt_text_manager.js index ebdd6a5d9..63a88a146 100644 --- a/web/alt_text_manager.js +++ b/web/alt_text_manager.js @@ -84,7 +84,7 @@ class AltTextManager { this.#currentEditor = editor; this.#uiManager = uiManager; - this.#uiManager.removeKeyboardManager(); + this.#uiManager.removeEditListeners(); this.#eventBus._on("resize", this.#boundSetPosition); try { @@ -158,7 +158,7 @@ class AltTextManager { } #close() { - this.#uiManager?.addKeyboardManager(); + this.#uiManager?.addEditListeners(); this.#eventBus._off("resize", this.#boundSetPosition); this.#currentEditor = null; this.#uiManager = null;