y-prosemirror
Advanced tools
Comparing version 1.2.5 to 1.2.6
@@ -57,7 +57,7 @@ export function isVisible(item: Y.Item, snapshot?: Y.Snapshot): boolean; | ||
/** | ||
* @param {Y.Snapshot} snapshot | ||
* @param {Y.Snapshot} prevSnapshot | ||
* @param {Y.Snapshot|Uint8Array} snapshot | ||
* @param {Y.Snapshot|Uint8Array} prevSnapshot | ||
* @param {Object} pluginState | ||
*/ | ||
_renderSnapshot(snapshot: Y.Snapshot, prevSnapshot: Y.Snapshot, pluginState: any): void; | ||
_renderSnapshot(snapshot: Y.Snapshot | Uint8Array, prevSnapshot: Y.Snapshot | Uint8Array, pluginState: any): void; | ||
/** | ||
@@ -64,0 +64,0 @@ * @param {Array<Y.YEvent<any>>} events |
{ | ||
"name": "y-prosemirror", | ||
"version": "1.2.5", | ||
"version": "1.2.6", | ||
"description": "Prosemirror bindings for Yjs", | ||
@@ -5,0 +5,0 @@ "main": "./dist/y-prosemirror.cjs", |
@@ -56,3 +56,3 @@ import { updateYFragment, createNodeFromYElement } from './plugins/sync-plugin.js' // eslint-disable-line | ||
if (pos === 0) { | ||
return Y.createRelativePositionFromTypeIndex(type, 0) | ||
return Y.createRelativePositionFromTypeIndex(type, 0, -1) | ||
} | ||
@@ -66,3 +66,3 @@ /** | ||
if (n._length >= pos) { | ||
return Y.createRelativePositionFromTypeIndex(n, pos) | ||
return Y.createRelativePositionFromTypeIndex(n, pos, -1) | ||
} else { | ||
@@ -121,3 +121,3 @@ pos -= n._length | ||
} | ||
return Y.createRelativePositionFromTypeIndex(type, type._length) | ||
return Y.createRelativePositionFromTypeIndex(type, type._length, -1) | ||
} | ||
@@ -124,0 +124,0 @@ |
@@ -395,2 +395,6 @@ /** | ||
this.mux(() => { | ||
// If this is a forced rerender, this might neither happen as a pm change nor within a Yjs | ||
// transaction. Then the "before selection" doesn't exist. In this case, we need to create a | ||
// relative position before replacing content. Fixes #126 | ||
const sel = this.beforeTransactionSelection !== null ? null : this.prosemirrorView.state.selection | ||
const fragmentContent = this.type.toArray().map((t) => | ||
@@ -409,2 +413,5 @@ createNodeFromYElement( | ||
) | ||
if (sel) { | ||
tr.setSelection(TextSelection.create(tr.doc, sel.anchor, sel.head)) | ||
} | ||
this.prosemirrorView.dispatch( | ||
@@ -417,14 +424,30 @@ tr.setMeta(ySyncPluginKey, { isChangeOrigin: true, binding: this }) | ||
/** | ||
* @param {Y.Snapshot} snapshot | ||
* @param {Y.Snapshot} prevSnapshot | ||
* @param {Y.Snapshot|Uint8Array} snapshot | ||
* @param {Y.Snapshot|Uint8Array} prevSnapshot | ||
* @param {Object} pluginState | ||
*/ | ||
_renderSnapshot (snapshot, prevSnapshot, pluginState) { | ||
/** | ||
* The document that contains the full history of this document. | ||
* @type {Y.Doc} | ||
*/ | ||
let historyDoc = this.doc | ||
if (!snapshot) { | ||
snapshot = Y.snapshot(this.doc) | ||
} | ||
if (snapshot instanceof Uint8Array || prevSnapshot instanceof Uint8Array) { | ||
if (!(snapshot instanceof Uint8Array) || !(prevSnapshot instanceof Uint8Array)) { | ||
// expected both snapshots to be v2 updates | ||
error.unexpectedCase() | ||
} | ||
historyDoc = new Y.Doc({ gc: false }) | ||
Y.applyUpdateV2(historyDoc, prevSnapshot) | ||
prevSnapshot = Y.snapshot(historyDoc) | ||
Y.applyUpdateV2(historyDoc, snapshot) | ||
snapshot = Y.snapshot(historyDoc) | ||
} | ||
// clear mapping because we are going to rerender | ||
this.mapping = new Map() | ||
this.mux(() => { | ||
this.doc.transact((transaction) => { | ||
historyDoc.transact((transaction) => { | ||
// before rendering, we are going to sanitize ops and split deleted ops | ||
@@ -431,0 +454,0 @@ // if they were deleted by seperate users. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
261558
4049