fix undoing of content containing subdocs

This commit is contained in:
Kevin Jahns
2021-11-19 13:47:10 +01:00
parent 4154b12f14
commit 9a7250f192
3 changed files with 25 additions and 13 deletions

View File

@@ -5,6 +5,12 @@ import {
import * as error from 'lib0/error'
/**
* @param {string} guid
* @param {Object<string, any>} opts
*/
const createDocFromOpts = (guid, opts) => new Doc({ guid, ...opts, shouldLoad: opts.shouldLoad || opts.autoLoad || false })
/**
* @private
*/
@@ -61,7 +67,7 @@ export class ContentDoc {
* @return {ContentDoc}
*/
copy () {
return new ContentDoc(this.doc)
return new ContentDoc(createDocFromOpts(this.doc.guid, this.opts))
}
/**
@@ -132,8 +138,4 @@ export class ContentDoc {
* @param {UpdateDecoderV1 | UpdateDecoderV2} decoder
* @return {ContentDoc}
*/
export const readContentDoc = decoder => {
const guid = decoder.readString()
const opts = decoder.readAny()
return new ContentDoc(new Doc({ guid, ...opts, shouldLoad: opts.shouldLoad || opts.autoLoad || false }))
}
export const readContentDoc = decoder => new ContentDoc(createDocFromOpts(decoder.readString(), decoder.readAny()))

View File

@@ -249,13 +249,8 @@ export class Doc extends Observable {
if (item !== null) {
this._item = null
const content = /** @type {ContentDoc} */ (item.content)
if (item.deleted) {
// @ts-ignore
content.doc = null
} else {
content.doc = new Doc({ guid: this.guid, ...content.opts, shouldLoad: false })
content.doc._item = item
}
content.doc = new Doc({ guid: this.guid, ...content.opts, shouldLoad: false })
content.doc._item = item
transact(/** @type {any} */ (item).parent.doc, transaction => {
const doc = content.doc
if (!item.deleted) {