From 9efe860f2636e35d724100f91d5a22cffd1480fa Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 11 Dec 2023 21:58:39 +0100 Subject: [PATCH] fix(editor): keep editor open when emptying content from the outside --- src/components/input/editor/TipTap.vue | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/input/editor/TipTap.vue b/src/components/input/editor/TipTap.vue index f7daa0901..bcc6fa8e1 100644 --- a/src/components/input/editor/TipTap.vue +++ b/src/components/input/editor/TipTap.vue @@ -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