From f6b4819ae3619469830dc5359ab4a08f2aab831b Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Thu, 31 Jan 2019 09:50:52 +0100 Subject: [PATCH] prosemirror: implement isChangeOrigin in state --- bindings/prosemirror.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bindings/prosemirror.js b/bindings/prosemirror.js index 7bd15c72..df11d635 100644 --- a/bindings/prosemirror.js +++ b/bindings/prosemirror.js @@ -45,7 +45,8 @@ export const prosemirrorPlugin = yXmlFragment => { type: yXmlFragment, y: yXmlFragment._y, binding: null, - snapshot: null + snapshot: null, + isChangeOrigin: false } }, apply: (tr, pluginState) => { @@ -56,6 +57,8 @@ export const prosemirrorPlugin = yXmlFragment => { pluginState[key] = change[key] } } + // always set isChangeOrigin. If undefined, this is not change origin. + pluginState.isChangeOrigin = change !== undefined && !!change.isChangeOrigin if (pluginState.binding !== null) { if (change !== undefined && change.snapshot !== undefined) { // snapshot changed, rerender next @@ -376,15 +379,16 @@ export class ProsemirrorBinding { transaction.changedTypes.forEach(delStruct) transaction.changedParentTypes.forEach(delStruct) const fragmentContent = this.type.toArray().map(t => createNodeIfNotExists(t, this.prosemirrorView.state.schema, this.mapping)).filter(n => n !== null) - const tr = this.prosemirrorView.state.tr.replace(0, this.prosemirrorView.state.doc.content.size, new PModel.Slice(new PModel.Fragment(fragmentContent), 0, 0)) + let tr = this.prosemirrorView.state.tr.replace(0, this.prosemirrorView.state.doc.content.size, new PModel.Slice(new PModel.Fragment(fragmentContent), 0, 0)) const relSel = this._relSelection if (relSel !== null && relSel.anchor !== null && relSel.head !== null) { const anchor = relativePositionToAbsolutePosition(this.type, relSel.anchor, this.mapping) const head = relativePositionToAbsolutePosition(this.type, relSel.head, this.mapping) if (anchor !== null && head !== null) { - tr.setSelection(TextSelection.create(tr.doc, anchor, head)) + tr = tr.setSelection(TextSelection.create(tr.doc, anchor, head)) } } + tr = tr.setMeta(prosemirrorPluginKey, { isChangeOrigin: true }) this.prosemirrorView.dispatch(tr) }) }