Skip to content

πŸ“š The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

Implement auto-save functionality in Markdown editor with user preference support

Axel MINARTc90eab5a459b
diff --git a/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vue b/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vue
index 2ceb6a8b..43d6fa4a 100644
--- a/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vue
+++ b/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vue
@@ -4,9 +4,9 @@
<div class="editor-container">
<Toolbar v-model="document" :minimal="minimal" @execute-action="exec" />
<div style="display: flex; min-height: 0; padding: 6px; flex: 1; flex-direction: column; gap: 8px">
- <input v-if="!minimal" v-model="document.name" placeholder="Title" class="title" />
- <input v-if="!minimal" v-model="document.description" placeholder="Description" class="description" />
- <AppTagInput v-model="document.tags" style="margin-bottom: 10px" />
+ <input v-if="!minimal" v-model="document.name" placeholder="Title" class="title" @input="autoSave" />
+ <input v-if="!minimal" v-model="document.description" placeholder="Description" class="description" @input="autoSave" />
+ <AppTagInput v-model="document.tags" style="margin-bottom: 10px" @update:model-value="autoSave" />
<div ref="container" class="markdown">
<div ref="editorContainer" class="codemirror-editor" style="border-right: 1px solid var(--border-color)" />
<!-- eslint-disable-next-line vue/no-v-html -->
@@ -41,6 +41,7 @@ import type { Document, Ressource } from '~/stores';
import { useModal, Modal } from '~/composables/ModalBus';
const resourcesStore = useRessourcesStore();
+const preferencesStore = usePreferences();
const props = defineProps<{ doc?: Partial<Document>; minimal?: boolean }>();
const emit = defineEmits(['save', 'exit']);
@@ -313,6 +314,11 @@ const updateListener = EditorView.updateListener.of(v => {
const content = v.state.doc.toString();
document.value.content_markdown = content;
document.value.content_html = compile(content);
+
+ if(preferencesStore.get('documentAutoSave').value){
+ // delayed autoSave
+ autoSave();
+ }
}
});
const state = EditorState.create({
@@ -378,6 +384,13 @@ const save = debounce(() => {
document.value.content_html = compile(content);
emit('save', document.value);
}, 1000);
+
+const autoSave = debounceDelayed(() => {
+ const content = editorView.value?.state.doc.toString() || '';
+ document.value.content_markdown = content;
+ document.value.content_html = compile(content);
+ emit('save', document.value);
+}, 2000)
</script>
<style scoped lang="scss">