Merge pull request #16982 from calixteman/alt_text_rm_copy_listeners

[Editor] Remove copy/paste listener when alt text dialog is displayed
This commit is contained in:
calixteman 2023-09-19 22:52:49 +02:00 committed by GitHub
commit 8d326e5e30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View File

@ -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,

View File

@ -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;