1
0

Use if to conditionally add escape hotkey

This commit is contained in:
Elscrux 2024-05-16 00:11:39 +02:00
parent 308a98c876
commit ecd44059e4

View File

@ -194,6 +194,7 @@ import {Extension, mergeAttributes} from '@tiptap/core'
import {isEditorContentEmpty} from '@/helpers/editorContentEmpty'
import inputPrompt from '@/helpers/inputPrompt'
import {setLinkInEditor} from '@/components/input/editor/setLinkInEditor'
import {Extensions} from '@tiptap/core/src/types'
const {
modelValue,
@ -325,10 +326,7 @@ watch(
},
)
const editor = useEditor({
// eslint-disable-next-line vue/no-ref-object-destructure
editable: isEditing.value,
extensions: [
const extensions : Extensions = [
// Starterkit:
Blockquote,
Bold,
@ -427,11 +425,11 @@ const editor = useEditor({
suggestion: suggestionSetup(t),
}),
BubbleMenu,
]
// Add a custom extension for the Escape key
...(
discardShortcutEnabled
?[discardShortcutEnabled && Extension.create({
// Add a custom extension for the Escape key
if (discardShortcutEnabled) {
extensions.push(Extension.create({
name: 'escapeKey',
addKeyboardShortcuts() {
@ -442,10 +440,13 @@ const editor = useEditor({
},
}
},
})]
: []
),
],
}))
}
const editor = useEditor({
// eslint-disable-next-line vue/no-ref-object-destructure
editable: isEditing.value,
extensions: extensions,
onUpdate: () => {
bubbleNow()
},