11<template >
22 <NcAppContent :class =" { loading: loading || isManualSave, 'icon-error': !loading && (!note || note.error), 'sidebar-open': sidebarOpen }" >
3- <div v-if =" !loading && note && !note.error && !note.deleting"
3+ <div class =" text-editor" v-if =" useTextEditor" ref =" editor" v-show =" !loading" ></div >
4+ <div v-else-if =" !loading && note && !note.error && !note.deleting"
45 id =" note-container"
56 class =" note-container"
67 :class =" { fullscreen: fullscreen }"
2728 </div >
2829 </div >
2930 </NcModal >
30- <div class =" note-editor" >
31+ <div class =" note-editor" v-else >
3132 <div v-show =" !note.content" class =" placeholder" >
3233 {{ preview ? t('notes', 'Empty note') : t('notes', 'Write …') }}
3334 </div >
@@ -154,6 +155,7 @@ export default {
154155
155156 data () {
156157 return {
158+ useTextEditor: true ,
157159 loading: false ,
158160 fullscreen: false ,
159161 preview: false ,
@@ -163,6 +165,7 @@ export default {
163165 refreshTimer: null ,
164166 etag: null ,
165167 showConflict: false ,
168+ editor: null ,
166169 }
167170 },
168171
@@ -217,8 +220,10 @@ export default {
217220 this .onUpdateTitle (null )
218221 },
219222
223+
224+
220225 methods: {
221- fetchData () {
226+ async fetchData () {
222227 this .etag = null
223228 this .stopRefreshTimer ()
224229
@@ -235,11 +240,38 @@ export default {
235240 showError (t (' notes' , ' Error from Nextcloud server: {msg}' , { msg: note .errorType }))
236241 }
237242 this .startRefreshTimer ()
243+ this .loadTextEditor ()
238244 })
239245 .catch (() => {
240246 // note not found
241247 })
242248 .then (() => {
249+ this .loading = this .useTextEditor || false
250+ })
251+ },
252+
253+ async loadTextEditor () {
254+ if (! this .useTextEditor ) {
255+ return
256+ }
257+ if (this .useTextEditor && ! this .$refs ? .editor ) {
258+ await this .$nextTick
259+ }
260+ this ? .editor ? .destroy ()
261+ this .loading = true
262+ this .editor = (await window .OCA .Text .createEditor ({
263+ el: this .$refs .editor ,
264+ fileId: parseInt (this .noteId ),
265+ readOnly: false ,
266+ onUpdate : ({ markdown }) => {
267+ if (this .note ) {
268+ this .onEdit (markdown)
269+ }
270+ // this.content = markdown
271+ // this.editorFile.setContent(markdown)
272+ },
273+ }))
274+ .onLoaded (() => {
243275 this .loading = false
244276 })
245277 },
@@ -299,6 +331,7 @@ export default {
299331 },
300332
301333 onVisibilityChange () {
334+ return ;
302335 if (document .visibilityState === ' visible' ) {
303336 this .stopRefreshTimer ()
304337 this .refreshNote ()
@@ -336,6 +369,21 @@ export default {
336369 },
337370
338371 onEdit (newContent ) {
372+ if (this .useTextEditor ) {
373+ const note = {
374+ ... this .note ,
375+ content: newContent,
376+ unsaved: true ,
377+ }
378+ store .commit (' updateNote' , note)
379+ if (this .isNewNote ) {
380+ queueCommand (note .id , ' autotitle' )
381+ }
382+ this .$forceUpdate ()
383+
384+ return
385+ }
386+
339387 if (this .note .content !== newContent) {
340388 this .stopRefreshTimer ()
341389 const note = {
@@ -376,6 +424,9 @@ export default {
376424 },
377425
378426 onKeyPress (event ) {
427+ if (this .useTextEditor ) {
428+ return
429+ }
379430 if (event .ctrlKey || event .metaKey ) {
380431 switch (event .key .toLowerCase ()) {
381432 case ' s' :
@@ -391,6 +442,10 @@ export default {
391442 },
392443
393444 onManualSave () {
445+ if (! this .useTextEditor ) {
446+ return
447+ }
448+
394449 const note = {
395450 ... this .note ,
396451 }
@@ -413,6 +468,10 @@ export default {
413468}
414469< / script>
415470< style scoped>
471+ .text - editor {
472+ height: 100 % ;
473+ }
474+
416475.note - container {
417476 min- height: 100 % ;
418477 width: 100 % ;
0 commit comments