Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: only initialize editor once
When we recover a session the editor already exists.
Start the syncing again as the polling backend is created from scratch.
Do not attach further events to the editor and do not reset the content.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud authored and juliusknorr committed Mar 6, 2023
commit f8bd87f865dceba5e833bf30d7a46d3b0f48864a
11 changes: 7 additions & 4 deletions cypress/e2e/sync.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@ describe('Sync', () => {
req.alias = 'deadSync'
}
})
cy.wait('@push', { timeout: 15000 + Cypress.config().defaultCommandTimeout })
cy.wait('@push', { timeout: 15000 + Cypress.config().defaultCommandTimeout })
cy.wait('@push', { timeout: 15000 + Cypress.config().defaultCommandTimeout })
cy.wait('@push', { timeout: 15000 + Cypress.config().defaultCommandTimeout })
cy.get('#editor-container .document-status')
.should('contain', 'File could not be loaded', { timeout: 10000 })
cy.get('#editor-container .document-status', { timeout: 30000 })
.should('not.contain', 'File could not be loaded')
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' })
.as('syncAfterRecovery')
cy.getContent().type('* more content added after the lost connection{enter}')
cy.wait('@syncAfterRecovery')
cy.closeFile()
cy.testName()
.then(name => cy.downloadFile(`/${name}.md`))
Expand Down
88 changes: 48 additions & 40 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,9 @@ export default {
this.currentSession = session
this.document = document
this.readOnly = document.readOnly
if (this.$editor) {
this.$editor.setOptions({ editable: !this.readOnly })
}
this.lock = this.$syncService.lock
localStorage.setItem('nick', this.currentSession.guestName)
this.setCurrentSession(this.currentSession)
Expand All @@ -498,47 +501,52 @@ export default {
(this.isRichEditor ? Promise.resolve() : loadSyntaxHighlight(language))
.then(() => {
const session = this.currentSession
this.$editor ||= createEditor({
language,
relativePath: this.relativePath,
session,
onCreate: ({ editor }) => {
this.$syncService.startSync()
},
onUpdate: ({ editor }) => {
// this.debugContent(editor)
const proseMirrorMarkdown = this.$syncService.serialize(editor.state.doc)
this.$parent.$emit('update:content', {
markdown: proseMirrorMarkdown,
})
},
extensions: [
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,
},
}),
Keymap.configure({
'Mod-s': () => {
this.$syncService.save()
return true
},
}),
],
enableRichEditing: this.isRichEditor,
})
this.hasEditor = true
if (!documentState && documentSource) {
this.setContent(documentSource, { addToHistory: false })
if (!this.$editor) {
this.$editor = createEditor({
language,
relativePath: this.relativePath,
session,
onCreate: ({ editor }) => {
this.$syncService.startSync()
},
onUpdate: ({ editor }) => {
// this.debugContent(editor)
const proseMirrorMarkdown = this.$syncService.serialize(editor.state.doc)
this.$parent.$emit('update:content', {
markdown: proseMirrorMarkdown,
})
},
extensions: [
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,
},
}),
Keymap.configure({
'Mod-s': () => {
this.$syncService.save()
return true
},
}),
],
enableRichEditing: this.isRichEditor,
})
this.hasEditor = true
if (!documentState && documentSource) {
this.setContent(documentSource, { addToHistory: false })
}
this.listenEditorEvents()
} else {
// $editor already existed. So this is a reconnect.
this.$syncService.startSync()
}
this.listenEditorEvents()

})

Expand Down