Skip to content

Commit

Permalink
refactor(Editor): separate rich and plain creation
Browse files Browse the repository at this point in the history
Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Oct 8, 2024
1 parent db052fb commit edec5d1
Showing 1 changed file with 33 additions and 28 deletions.
61 changes: 33 additions & 28 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -520,35 +520,40 @@ export default {
return
}
const language = extensionHighlight[this.fileExtension] || this.fileExtension;
(this.isRichEditor ? Promise.resolve() : loadSyntaxHighlight(language))
.then(() => {
const session = this.currentSession
const extensions = [
Autofocus.configure({ fileId: this.fileId }),
Collaboration.configure({ document: this.$ydoc }),
CollaborationCursor.configure({
provider: this.$providers[0],
user: {
name: session?.userId
? session.displayName
: (session?.guestName || t('text', 'Guest')),
color: session?.color,
clientId: this.$ydoc.clientID,
},
}),
]
this.$editor = this.isRichEditor
? createRichEditor({
relativePath: this.relativePath,
session,
extensions,
isEmbedded: this.isEmbedded,
})
: createPlainEditor({ language, extensions })
this.hasEditor = true
this.listenEditorEvents()
const session = this.currentSession
const extensions = [
Autofocus.configure({ fileId: this.fileId }),
Collaboration.configure({ document: this.$ydoc }),
CollaborationCursor.configure({
provider: this.$providers[0],
user: {
name: session?.userId
? session.displayName
: (session?.guestName || t('text', 'Guest')),
color: session?.color,
clientId: this.$ydoc.clientID,
},
}),
]
if (this.isRichEditor) {
this.$editor = createRichEditor({
relativePath: this.relativePath,
session,
extensions,
isEmbedded: this.isEmbedded,
})
this.hasEditor = true
this.listenEditorEvents()
} else {
const language = extensionHighlight[this.fileExtension]
|| this.fileExtension
loadSyntaxHighlight(language)
.then(() => {
this.$editor = createPlainEditor({ language, extensions })
this.hasEditor = true
this.listenEditorEvents()
})
}
},
Expand Down

0 comments on commit edec5d1

Please sign in to comment.