Add discardShortcutEnabled setting to opt into this feature

Only editing the task description and comments have this feature enabled
This commit is contained in:
Elscrux 2024-04-26 17:22:02 +02:00
parent 0b7a9c09c5
commit 0e6fea95cb
3 changed files with 22 additions and 13 deletions

View File

@ -203,6 +203,7 @@ const {
showSave = false,
placeholder = '',
editShortcut = '',
discardShortcutEnabled = false,
} = defineProps<{
modelValue: string,
uploadCallback?: UploadCallback,
@ -211,6 +212,7 @@ const {
showSave?: boolean,
placeholder?: string,
editShortcut?: string,
discardShortcutEnabled?: boolean,
}>()
const emit = defineEmits(['update:modelValue', 'save'])
@ -351,19 +353,6 @@ const editor = useEditor({
}
},
}),
// Add a custom extension for the Escape key
Extension.create({
name: 'escapeKey',
addKeyboardShortcuts() {
return {
'Escape': () => {
exitEditMode()
return true
},
}
},
}),
Heading,
History,
HorizontalRule,
@ -438,6 +427,24 @@ const editor = useEditor({
suggestion: suggestionSetup(t),
}),
BubbleMenu,
// Add a custom extension for the Escape key
...(
discardShortcutEnabled
?[discardShortcutEnabled && Extension.create({
name: 'escapeKey',
addKeyboardShortcuts() {
return {
'Escape': () => {
exitEditMode()
return true
},
}
},
})]
: []
),
],
onUpdate: () => {
bubbleNow()

View File

@ -85,6 +85,7 @@
:upload-enabled="true"
:bottom-actions="actions[c.id]"
:show-save="true"
:discard-shortcut-enabled="true"
initial-mode="preview"
@update:modelValue="
() => {

View File

@ -30,6 +30,7 @@
:placeholder="$t('task.description.placeholder')"
:show-save="true"
edit-shortcut="e"
:discard-shortcut-enabled="true"
@update:modelValue="saveWithDelay"
@save="save"
/>