mirror of
https://github.com/go-vikunja/vikunja.git
synced 2025-12-05 19:16:51 -06:00
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:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user