@@ -476,6 +476,9 @@ export default {
476476 this .currentSession = session
477477 this .document = document
478478 this .readOnly = document .readOnly
479+ if (this .$editor ) {
480+ this .$editor .setOptions ({ editable: ! this .readOnly })
481+ }
479482 this .lock = this .$syncService .lock
480483 localStorage .setItem (' nick' , this .currentSession .guestName )
481484 this .setCurrentSession (this .currentSession )
@@ -498,47 +501,52 @@ export default {
498501 (this .isRichEditor ? Promise .resolve () : loadSyntaxHighlight (language))
499502 .then (() => {
500503 const session = this .currentSession
501- this .$editor || = createEditor ({
502- language,
503- relativePath: this .relativePath ,
504- session,
505- onCreate : ({ editor }) => {
506- this .$syncService .startSync ()
507- },
508- onUpdate : ({ editor }) => {
509- // this.debugContent(editor)
510- const proseMirrorMarkdown = this .$syncService .serialize (editor .state .doc )
511- this .$parent .$emit (' update:content' , {
512- markdown: proseMirrorMarkdown,
513- })
514- },
515- extensions: [
516- Collaboration .configure ({
517- document : this .$ydoc ,
518- }),
519- CollaborationCursor .configure ({
520- provider: this .$providers [0 ],
521- user: {
522- name: session? .userId
523- ? session .displayName
524- : (session? .guestName || t (' text' , ' Guest' )),
525- color: session? .color ,
526- },
527- }),
528- Keymap .configure ({
529- ' Mod-s ' : () => {
530- this .$syncService .save ()
531- return true
532- },
533- }),
534- ],
535- enableRichEditing: this .isRichEditor ,
536- })
537- this .hasEditor = true
538- if (! documentState && documentSource) {
539- this .setContent (documentSource, { addToHistory: false })
504+ if (! this .$editor ) {
505+ this .$editor = createEditor ({
506+ language,
507+ relativePath: this .relativePath ,
508+ session,
509+ onCreate : ({ editor }) => {
510+ this .$syncService .startSync ()
511+ },
512+ onUpdate : ({ editor }) => {
513+ // this.debugContent(editor)
514+ const proseMirrorMarkdown = this .$syncService .serialize (editor .state .doc )
515+ this .$parent .$emit (' update:content' , {
516+ markdown: proseMirrorMarkdown,
517+ })
518+ },
519+ extensions: [
520+ Collaboration .configure ({
521+ document : this .$ydoc ,
522+ }),
523+ CollaborationCursor .configure ({
524+ provider: this .$providers [0 ],
525+ user: {
526+ name: session? .userId
527+ ? session .displayName
528+ : (session? .guestName || t (' text' , ' Guest' )),
529+ color: session? .color ,
530+ },
531+ }),
532+ Keymap .configure ({
533+ ' Mod-s ' : () => {
534+ this .$syncService .save ()
535+ return true
536+ },
537+ }),
538+ ],
539+ enableRichEditing: this .isRichEditor ,
540+ })
541+ this .hasEditor = true
542+ if (! documentState && documentSource) {
543+ this .setContent (documentSource, { addToHistory: false })
544+ }
545+ this .listenEditorEvents ()
546+ } else {
547+ // $editor already existed. So this is a reconnect.
548+ this .$syncService .startSync ()
540549 }
541- this .listenEditorEvents ()
542550
543551 })
544552
0 commit comments