fix(editor): keep editor open when emptying content from the outside

This commit is contained in:
kolaente 2023-12-11 21:58:39 +01:00
parent af13d68c48
commit 9efe860f26
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 7 additions and 3 deletions

View File

@ -394,7 +394,7 @@ watch(
return
}
editor.value.commands.setContent(value, false)
setModeAndValue(value)
},
{immediate: true},
)
@ -501,8 +501,7 @@ onMounted(async () => {
const input = tiptapInstanceRef.value?.querySelectorAll('.tiptap__editor')[0]?.children[0]
input?.addEventListener('paste', handleImagePaste)
internalMode.value = isEditorContentEmpty(modelValue) ? 'edit' : 'preview'
editor.value?.commands.setContent(modelValue, false)
setModeAndValue(modelValue)
})
onBeforeUnmount(() => {
@ -515,6 +514,11 @@ onBeforeUnmount(() => {
}
})
function setModeAndValue(value: string) {
internalMode.value = isEditorContentEmpty(value) ? 'edit' : 'preview'
editor.value?.commands.setContent(value, false)
}
function handleImagePaste(event) {
if (event?.clipboardData?.items?.length === 0) {
return