From 1b829f4b751fb7e35691dd99d089b0201af56d55 Mon Sep 17 00:00:00 2001 From: guqing Date: Fri, 19 Jul 2024 12:53:18 +0800 Subject: [PATCH] fix: content update --- build.gradle | 2 +- ui/src/views/WillowMde.vue | 46 +++++++++++++------------------------- 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/build.gradle b/build.gradle index 91f6ab2..9d18987 100644 --- a/build.gradle +++ b/build.gradle @@ -48,5 +48,5 @@ build { } halo { - version = '2.14.0' + version = '2.17' } diff --git a/ui/src/views/WillowMde.vue b/ui/src/views/WillowMde.vue index 1c6da04..fef7a6b 100644 --- a/ui/src/views/WillowMde.vue +++ b/ui/src/views/WillowMde.vue @@ -22,7 +22,6 @@ const hasEscKeyMapping = (vimEscKeyMapping: string | undefined) => { }; const willow: Ref = ref(null); -const markdown = ref(""); const editor = ref(); const props = withDefaults( @@ -36,27 +35,8 @@ const props = withDefaults( } ); -const emit = defineEmits<{ - (event: "update:raw", value: string): void; - (event: "update:content", value: string): void; - (event: "update", value: string): void; -}>(); - -// debounce OnUpdate -const debounceOnUpdate = useDebounceFn(() => { - emit("update:raw", markdown.value); - emit("update:content", html.value || ""); - emit("update", markdown.value); -}, 250); - const options: Ink.Options = reactive({ - doc: markdown.value, - hooks: { - afterUpdate: (doc: string) => { - markdown.value = doc; - debounceOnUpdate(); - }, - }, + doc: props.raw, files: { clipboard: false, dragAndDrop: false, @@ -105,27 +85,33 @@ const options: Ink.Options = reactive({ vim: false, }); +const emit = defineEmits<{ + (event: "update:raw", value: string): void; + (event: "update:content", value: string): void; + (event: "update", value: string): void; +}>(); + +// debounce OnUpdate +const debounceOnUpdate = useDebounceFn(() => { + emit("update:raw", options.doc || ""); + emit("update:content", html.value || ""); + emit("update", options.doc || ""); +}, 250); + options.plugins?.push(willowLightTheme, selectionMark); watch(options, (newValue) => { if (editor.value) { editor.value.reconfigure(newValue); - } -}); - -watch(markdown, (newValue) => { - if (editor.value?.getDoc() !== newValue) { - editor.value?.update(newValue); + debounceOnUpdate(); } }); const html = computedAsync(async () => { - return await renderToHtml(markdown.value); + return await renderToHtml(options.doc || ""); }, null); onMounted(async () => { - markdown.value = props.raw; - if (willow.value) { editor.value = ink(willow.value, options);