1
1
<template >
2
2
<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"
4
5
id =" note-container"
5
6
class =" note-container"
6
7
:class =" { fullscreen: fullscreen }"
27
28
</div >
28
29
</div >
29
30
</NcModal >
30
- <div class =" note-editor" >
31
+ <div class =" note-editor" v-else >
31
32
<div v-show =" !note.content" class =" placeholder" >
32
33
{{ preview ? t('notes', 'Empty note') : t('notes', 'Write …') }}
33
34
</div >
@@ -154,6 +155,7 @@ export default {
154
155
155
156
data () {
156
157
return {
158
+ useTextEditor: true ,
157
159
loading: false ,
158
160
fullscreen: false ,
159
161
preview: false ,
@@ -163,6 +165,7 @@ export default {
163
165
refreshTimer: null ,
164
166
etag: null ,
165
167
showConflict: false ,
168
+ editor: null ,
166
169
}
167
170
},
168
171
@@ -217,8 +220,10 @@ export default {
217
220
this .onUpdateTitle (null )
218
221
},
219
222
223
+
224
+
220
225
methods: {
221
- fetchData () {
226
+ async fetchData () {
222
227
this .etag = null
223
228
this .stopRefreshTimer ()
224
229
@@ -235,11 +240,38 @@ export default {
235
240
showError (t (' notes' , ' Error from Nextcloud server: {msg}' , { msg: note .errorType }))
236
241
}
237
242
this .startRefreshTimer ()
243
+ this .loadTextEditor ()
238
244
})
239
245
.catch (() => {
240
246
// note not found
241
247
})
242
248
.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 (() => {
243
275
this .loading = false
244
276
})
245
277
},
@@ -299,6 +331,7 @@ export default {
299
331
},
300
332
301
333
onVisibilityChange () {
334
+ return ;
302
335
if (document .visibilityState === ' visible' ) {
303
336
this .stopRefreshTimer ()
304
337
this .refreshNote ()
@@ -336,6 +369,21 @@ export default {
336
369
},
337
370
338
371
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
+
339
387
if (this .note .content !== newContent) {
340
388
this .stopRefreshTimer ()
341
389
const note = {
@@ -376,6 +424,9 @@ export default {
376
424
},
377
425
378
426
onKeyPress (event ) {
427
+ if (this .useTextEditor ) {
428
+ return
429
+ }
379
430
if (event .ctrlKey || event .metaKey ) {
380
431
switch (event .key .toLowerCase ()) {
381
432
case ' s' :
@@ -391,6 +442,10 @@ export default {
391
442
},
392
443
393
444
onManualSave () {
445
+ if (! this .useTextEditor ) {
446
+ return
447
+ }
448
+
394
449
const note = {
395
450
... this .note ,
396
451
}
@@ -413,6 +468,10 @@ export default {
413
468
}
414
469
< / script>
415
470
< style scoped>
471
+ .text - editor {
472
+ height: 100 % ;
473
+ }
474
+
416
475
.note - container {
417
476
min- height: 100 % ;
418
477
width: 100 % ;
0 commit comments