From 499a54f9585c9935117bb511ae3abc6477bc05bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 2 Apr 2024 12:48:25 +0200 Subject: [PATCH] fix: Adapt to review feedback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- src/components/CollisionResolveDialog.vue | 2 +- src/components/Editor.vue | 2 +- src/mixins/setContent.js | 15 ++++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/components/CollisionResolveDialog.vue b/src/components/CollisionResolveDialog.vue index 7de994c7d0..304f7724d3 100644 --- a/src/components/CollisionResolveDialog.vue +++ b/src/components/CollisionResolveDialog.vue @@ -71,7 +71,7 @@ export default { const { outsideChange } = this.syncError.data this.clicked = true this.$editor.setEditable(!this.readOnly) - this.setContent(outsideChange, { isRich: this.$isRichEditor }) + this.setContent(outsideChange, { isRichEditor: this.$isRichEditor }) this.$syncService.forceSave().then(() => this.$syncService.syncUp()) }, }, diff --git a/src/components/Editor.vue b/src/components/Editor.vue index 37edf93f0a..af9c639a69 100644 --- a/src/components/Editor.vue +++ b/src/components/Editor.vue @@ -495,7 +495,7 @@ export default { this.$queue.push(updateMessage) } } else { - this.setInitialYjsState(documentSource, { isRich: this.isRichEditor }) + this.setInitialYjsState(documentSource, { isRichEditor: this.isRichEditor }) } this.hasConnectionIssue = false diff --git a/src/mixins/setContent.js b/src/mixins/setContent.js index 39e0a1091b..0126fde566 100644 --- a/src/mixins/setContent.js +++ b/src/mixins/setContent.js @@ -30,8 +30,8 @@ import { createEditor } from '../EditorFactory.js' export default { methods: { - setContent(content, { isRich, addToHistory = true } = {}) { - const html = isRich + setContent(content, { isRichEditor, addToHistory = true } = {}) { + const html = isRichEditor ? markdownit.render(content) + '

' : `

${escapeHtml(content)}
` this.$editor.chain() @@ -43,13 +43,13 @@ export default { .run() }, - setInitialYjsState(content, { isRich }) { - const html = isRich + setInitialYjsState(content, { isRichEditor }) { + const html = isRichEditor ? markdownit.render(content) + '

' : `

${escapeHtml(content)}
` const editor = createEditor({ - enableRichEditing: isRich, + enableRichEditing: isRichEditor, }) const json = generateJSON(html, editor.extensionManager.extensions) @@ -58,14 +58,15 @@ export default { const ydoc = new Doc() // In order to make the initial document state idempotent, we need to reset the clientID // While this is not recommended, we cannot avoid it here as we lack another mechanism - // generate the initial state on the server side + // to generate the initial state on the server side // The only other option to avoid this could be to generate the initial state once and push // it to the server immediately, however this would require read only sessions to be able // to still push a state ydoc.clientID = 0 const type = /** @type {XmlFragment} */ (ydoc.get('default', XmlFragment)) if (!type.doc) { - prosemirrorToYXmlFragment(doc, ydoc) + // This should not happen but is aligned with the upstream implementation + // https://github.com/yjs/y-prosemirror/blob/8db24263770c2baaccb08e08ea9ef92dbcf8a9da/src/lib.js#L209 return ydoc }