fix(editor): close only editor when pressing escape

This fixes a bug where when the task was opened in a modal and the user was editing the description and then pressing escape it would also close the task modal instead of only escaping from the editor itself.
This commit is contained in:
kolaente
2025-11-27 22:24:22 +01:00
parent 6bee4a40ae
commit 9626382667

View File

@@ -644,7 +644,13 @@ function setEdit(focus: boolean = true) {
}
}
onBeforeUnmount(() => editor.value?.destroy())
onBeforeUnmount(() => {
if (props.enableDiscardShortcut) {
tiptapInstanceRef.value?.removeEventListener('keydown', handleEscapeKey)
}
editor.value?.destroy()
})
const uploadInputRef = ref<HTMLInputElement | null>(null)
@@ -721,6 +727,11 @@ onMounted(async () => {
document.addEventListener('keydown', setFocusToEditor)
}
// Add Escape key handler to prevent event bubbling when editing
if (props.enableDiscardShortcut) {
tiptapInstanceRef.value?.addEventListener('keydown', handleEscapeKey)
}
await nextTick()
// Load draft from localStorage if available
@@ -786,6 +797,24 @@ function focusIfEditing() {
}
}
function handleEscapeKey(event: KeyboardEvent) {
// Only intercept Escape when discard shortcut is enabled
if (event.key !== 'Escape' || !props.enableDiscardShortcut) {
return
}
// Check if the event originated from within the ProseMirror editor
const target = event.target as HTMLElement
const isInEditor = target.contentEditable === 'true' || target.closest('.ProseMirror')
if (!isInEditor) {
return
}
// Stop propagation to prevent modal/parent handlers from firing
event.stopPropagation()
// Don't preventDefault - let ProseMirror's extension handle the actual exit
}
function clickTasklistCheckbox(event: MouseEvent) {
event.stopImmediatePropagation()