@@ -30,6 +30,7 @@ export default {
30
30
return {
31
31
loading: false ,
32
32
editor: null ,
33
+ shouldAutotitle: true ,
33
34
}
34
35
},
35
36
@@ -83,13 +84,19 @@ export default {
83
84
}
84
85
this ? .editor ? .destroy ()
85
86
this .loading = true
87
+ this .shouldAutotitle = undefined
86
88
this .editor = (await window .OCA .Text .createEditor ({
87
89
el: this .$refs .editor ,
88
90
fileId: parseInt (this .noteId ),
89
91
readOnly: false ,
90
92
onUpdate : ({ markdown }) => {
91
93
if (this .note ) {
92
- this .onEdit ({ content: markdown, unsaved: true })
94
+ const unsaved = !! (this .note ? .content && this .note .content !== markdown)
95
+ if (this .shouldAutotitle === undefined ) {
96
+ const title = this .getTitle (markdown)
97
+ this .shouldAutotitle = this .isNewNote || (title !== ' ' && title === this .note .title )
98
+ }
99
+ this .onEdit ({ content: markdown, unsaved: unsaved})
93
100
}
94
101
},
95
102
}))
@@ -108,9 +115,26 @@ export default {
108
115
fileUpdated ({ fileid }) {
109
116
if (this .note .id === fileid) {
110
117
this .onEdit ({ unsaved: false })
111
- queueCommand (fileid, ' autotitle' )
118
+ if (this .shouldAutotitle ) {
119
+ queueCommand (fileid, ' autotitle' )
120
+ }
112
121
}
113
122
},
123
+
124
+ getTitle (content ) {
125
+ const firstLine = content .split (' \n ' )[0 ] ?? ' '
126
+ const title = firstLine
127
+ // See NoteUtil::sanitisePath
128
+ .replaceAll (/ ^ \s * [*+-] \s + / gmu , ' ' )
129
+ .replaceAll (/ ^ [.\s ] + / gmu , ' ' )
130
+ .replaceAll (/ \* | \| | \/ | \\ | :| "| '| <| >| \? / gmu , ' ' )
131
+ // See NoteUtil::stripMarkdown
132
+ .replaceAll (/ ^ #+ \s + (. *? )\s * #* $ / gmu , ' $1' )
133
+ .replaceAll (/ ^ (=+ | -+ )$ / gmu , ' ' )
134
+ .replaceAll (/ (\* + | _+ )(. *? )\\ 1/ gmu , ' $2' )
135
+ .replaceAll (/ \s / gmu , ' ' )
136
+ return title .length > 0 ? title : t (' notes' , ' New note' )
137
+ },
114
138
},
115
139
}
116
140
< / script>
0 commit comments