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() { destroy() {
this.removeKeyboardManager(); this.#removeKeyboardManager();
this.#removeFocusManager(); this.#removeFocusManager();
this.#eventBus._off("editingaction", this.#boundOnEditingAction); this.#eventBus._off("editingaction", this.#boundOnEditingAction);
this.#eventBus._off("pagechanging", this.#boundOnPageChanging); this.#eventBus._off("pagechanging", this.#boundOnPageChanging);
@ -875,13 +875,13 @@ class AnnotationEditorUIManager {
lastActiveElement.focus(); lastActiveElement.focus();
} }
addKeyboardManager() { #addKeyboardManager() {
// The keyboard events are caught at the container level in order to be able // 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. // to execute some callbacks even if the current page doesn't have focus.
window.addEventListener("keydown", this.#boundKeydown, { capture: true }); window.addEventListener("keydown", this.#boundKeydown, { capture: true });
} }
removeKeyboardManager() { #removeKeyboardManager() {
window.removeEventListener("keydown", this.#boundKeydown, { window.removeEventListener("keydown", this.#boundKeydown, {
capture: true, capture: true,
}); });
@ -899,6 +899,16 @@ class AnnotationEditorUIManager {
document.removeEventListener("paste", this.#boundPaste); document.removeEventListener("paste", this.#boundPaste);
} }
addEditListeners() {
this.#addKeyboardManager();
this.#addCopyPasteListeners();
}
removeEditListeners() {
this.#removeKeyboardManager();
this.#removeCopyPasteListeners();
}
/** /**
* Copy callback. * Copy callback.
* @param {ClipboardEvent} event * @param {ClipboardEvent} event
@ -1054,7 +1064,7 @@ class AnnotationEditorUIManager {
setEditingState(isEditing) { setEditingState(isEditing) {
if (isEditing) { if (isEditing) {
this.#addFocusManager(); this.#addFocusManager();
this.addKeyboardManager(); this.#addKeyboardManager();
this.#addCopyPasteListeners(); this.#addCopyPasteListeners();
this.#dispatchUpdateStates({ this.#dispatchUpdateStates({
isEditing: this.#mode !== AnnotationEditorType.NONE, isEditing: this.#mode !== AnnotationEditorType.NONE,
@ -1065,7 +1075,7 @@ class AnnotationEditorUIManager {
}); });
} else { } else {
this.#removeFocusManager(); this.#removeFocusManager();
this.removeKeyboardManager(); this.#removeKeyboardManager();
this.#removeCopyPasteListeners(); this.#removeCopyPasteListeners();
this.#dispatchUpdateStates({ this.#dispatchUpdateStates({
isEditing: false, isEditing: false,

View File

@ -84,7 +84,7 @@ class AltTextManager {
this.#currentEditor = editor; this.#currentEditor = editor;
this.#uiManager = uiManager; this.#uiManager = uiManager;
this.#uiManager.removeKeyboardManager(); this.#uiManager.removeEditListeners();
this.#eventBus._on("resize", this.#boundSetPosition); this.#eventBus._on("resize", this.#boundSetPosition);
try { try {
@ -158,7 +158,7 @@ class AltTextManager {
} }
#close() { #close() {
this.#uiManager?.addKeyboardManager(); this.#uiManager?.addEditListeners();
this.#eventBus._off("resize", this.#boundSetPosition); this.#eventBus._off("resize", this.#boundSetPosition);
this.#currentEditor = null; this.#currentEditor = null;
this.#uiManager = null; this.#uiManager = null;