Skip to content

Commit

Permalink
feat: handle composition
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentdchan committed May 7, 2022
1 parent e3755b1 commit 15be62f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/plugins/sync-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ export const ySyncPlugin = (yXmlFragment, { colors = defaultColors, colorMapping
const pluginState = plugin.getState(view.state)
if (pluginState.snapshot == null && pluginState.prevSnapshot == null) {
if (changedInitialContent || view.state.doc.content.findDiffStart(view.state.doc.type.createAndFill().content) !== null) {
// if the dom is composing, don't sync
if (pluginState.binding && pluginState.binding.prosemirrorView.composing) {
return
}
changedInitialContent = true
binding._prosemirrorChanged(view.state.doc)
}
Expand Down Expand Up @@ -195,6 +199,13 @@ export class ProsemirrorBinding {
constructor (yXmlFragment, prosemirrorView) {
this.type = yXmlFragment
this.prosemirrorView = prosemirrorView

// When composition finished, no transaction will be committed.
// So we need to hook the event to commit the changes.
prosemirrorView.dom.addEventListener('compositionend', () => {
this._prosemirrorChanged(prosemirrorView.state.doc)
})

this.mux = createMutex()
this.isDestroyed = false
/**
Expand Down

0 comments on commit 15be62f

Please sign in to comment.