Skip to content

Commit

Permalink
[Editor] Remove copy/paste listener when alt text dialog is displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
calixteman committed Sep 19, 2023
1 parent 54f6264 commit c162b00
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
20 changes: 15 additions & 5 deletions src/display/editor/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
});
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -1065,7 +1075,7 @@ class AnnotationEditorUIManager {
});
} else {
this.#removeFocusManager();
this.removeKeyboardManager();
this.#removeKeyboardManager();
this.#removeCopyPasteListeners();
this.#dispatchUpdateStates({
isEditing: false,
Expand Down
4 changes: 2 additions & 2 deletions web/alt_text_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c162b00

Please sign in to comment.