Skip to content

Commit

Permalink
fix: Adapt to review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr authored and mejo- committed Apr 2, 2024
1 parent 05fa813 commit cd524da
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/CollisionResolveDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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())
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ export default {
this.$queue.push(updateMessage)
}
} else {
this.setInitialYjsState(documentSource, { isRich: this.isRichEditor })
this.setInitialYjsState(documentSource, { isRichEditor: this.isRichEditor })
}

this.hasConnectionIssue = false
Expand Down
15 changes: 8 additions & 7 deletions src/mixins/setContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) + '<p/>'
: `<pre>${escapeHtml(content)}</pre>`
this.$editor.chain()
Expand All @@ -43,13 +43,13 @@ export default {
.run()
},

setInitialYjsState(content, { isRich }) {
const html = isRich
setInitialYjsState(content, { isRichEditor }) {
const html = isRichEditor
? markdownit.render(content) + '<p/>'
: `<pre>${escapeHtml(content)}</pre>`

const editor = createEditor({
enableRichEditing: isRich,
enableRichEditing: isRichEditor,
})
const json = generateJSON(html, editor.extensionManager.extensions)

Expand All @@ -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
}

Expand Down

0 comments on commit cd524da

Please sign in to comment.