Skip to content

Commit

Permalink
fix: content update
Browse files Browse the repository at this point in the history
  • Loading branch information
guqing committed Jul 19, 2024
1 parent 2e9247b commit 1b829f4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 31 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ build {
}

halo {
version = '2.14.0'
version = '2.17'
}
46 changes: 16 additions & 30 deletions ui/src/views/WillowMde.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const hasEscKeyMapping = (vimEscKeyMapping: string | undefined) => {
};
const willow: Ref<HTMLElement | null> = ref(null);
const markdown = ref("");
const editor = ref<Ink.Instance>();
const props = withDefaults(
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1b829f4

Please sign in to comment.