From 8e53595b4f95aba83c2ddad2103b743f4de132dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Sun, 16 Jul 2023 12:25:47 +0200 Subject: [PATCH 1/3] fix: Only use autotitle if the filename is unchanged MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- src/components/NoteRich.vue | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/components/NoteRich.vue b/src/components/NoteRich.vue index 305c06097..1e200e2ae 100644 --- a/src/components/NoteRich.vue +++ b/src/components/NoteRich.vue @@ -30,6 +30,7 @@ export default { return { loading: false, editor: null, + shouldAutotitle: true, } }, @@ -83,13 +84,19 @@ export default { } this?.editor?.destroy() this.loading = true + this.shouldAutotitle = undefined this.editor = (await window.OCA.Text.createEditor({ el: this.$refs.editor, fileId: parseInt(this.noteId), readOnly: false, onUpdate: ({ markdown }) => { if (this.note) { - this.onEdit({ content: markdown, unsaved: true }) + const unsaved = !!(this.note?.content && this.note.content !== markdown) + if (this.shouldAutotitle === undefined) { + const title = this.getTitle(markdown) + this.shouldAutotitle = this.isNewNote || (title !== '' && title === this.note.title) + } + this.onEdit({ content: markdown, unsaved: unsaved}) } }, })) @@ -108,9 +115,26 @@ export default { fileUpdated({ fileid }) { if (this.note.id === fileid) { this.onEdit({ unsaved: false }) - queueCommand(fileid, 'autotitle') + if (this.shouldAutotitle) { + queueCommand(fileid, 'autotitle') + } } }, + + getTitle(content) { + const firstLine = content.split('\n')[0] ?? '' + const title = firstLine + // See NoteUtil::sanitisePath + .replaceAll(/^\s*[*+-]\s+/gmu, '') + .replaceAll(/^[.\s]+/gmu, '') + .replaceAll(/\*|\||\/|\\|:|"|'|<|>|\?/gmu, '') + // See NoteUtil::stripMarkdown + .replaceAll(/^#+\s+(.*?)\s*#*$/gmu, '$1') + .replaceAll(/^(=+|-+)$/gmu, '') + .replaceAll(/(\*+|_+)(.*?)\\1/gmu, '$2') + .replaceAll(/\s/gmu, ' ') + return title.length > 0 ? title : t('notes', 'New note') + }, }, } From 48a57d690f04deacc52878bbf728aa40b345c36d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Sun, 16 Jul 2023 12:26:17 +0200 Subject: [PATCH 2/3] fix: Avoid flaky note mode checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- src/components/Note.vue | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/Note.vue b/src/components/Note.vue index a1e035791..b3f03b176 100644 --- a/src/components/Note.vue +++ b/src/components/Note.vue @@ -1,6 +1,7 @@