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