diff --git a/src/types/AbstractType.js b/src/types/AbstractType.js index c1856d34..62119035 100644 --- a/src/types/AbstractType.js +++ b/src/types/AbstractType.js @@ -514,15 +514,15 @@ export const typeListGetContent = (type, am) => { for (let item = type._start; item !== null; cs.length = 0) { // populate cs for (; item !== null && cs.length < 50; item = item.right) { - am.readContent(cs, item.id.client, item.id.clock, item.deleted, item.content, true) + am.readContent(cs, item.id.client, item.id.clock, item.deleted, item.content, !item.deleted) } for (let i = 0; i < cs.length; i++) { const c = cs[i] const attribution = createAttributionFromAttributionItems(c.attrs, c.deleted).attribution if (c.content.isCountable()) { - if (c.render) { + if (c.render || attribution != null) { d.insert(c.content.getContent(), null, attribution) - } else { + } else if (!c.deleted) { d.retain(c.content.getLength()) } } @@ -1011,7 +1011,7 @@ export const typeMapGetContent = (parent, am) => { * @type {Array>} */ const cs = [] - am.readContent(cs, item.id.client, item.id.clock, item.deleted, item.content, true) + am.readContent(cs, item.id.client, item.id.clock, item.deleted, item.content, !item.deleted) const { deleted, attrs, content } = cs[cs.length - 1] const c = array.last(content.getContent()) const { attribution } = createAttributionFromAttributionItems(attrs, deleted) @@ -1027,7 +1027,7 @@ export const typeMapGetContent = (parent, am) => { * @type {Array>} */ const tmpcs = [] - am.readContent(tmpcs, prevItem.id.client, prevItem.id.clock, prevItem.deleted, prevItem.content, true) + am.readContent(tmpcs, prevItem.id.client, prevItem.id.clock, prevItem.deleted, prevItem.content, !prevItem.deleted) cs = tmpcs.concat(cs) if (cs.length === 0 || cs[0].attrs == null) { cs.splice(0, cs.findIndex(c => c.attrs != null)) diff --git a/src/types/YText.js b/src/types/YText.js index 16c37e2a..8e46f746 100644 --- a/src/types/YText.js +++ b/src/types/YText.js @@ -25,7 +25,10 @@ import { ContentType, warnPrematureAccess, noAttributionsManager, AbstractAttributionManager, ArraySearchMarker, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Item, Transaction, // eslint-disable-line - createAttributionFromAttributionItems + createAttributionFromAttributionItems, + mergeIdSets, + diffIdSet, + intersectSets } from '../internals.js' import * as delta from '../utils/Delta.js' @@ -775,6 +778,16 @@ export class YTextEvent extends YEvent { } }) return d.done() + // const whatToWatch = mergeIdSets([diffIdSet(this.transaction.insertSet, this.transaction.deleteSet), diffIdSet(this.transaction.deleteSet, this.transaction.insertSet)]) + // const genericDelta = this.target.getDelta(am, whatToWatch) + // if (!d.equals(genericDelta)) { + // console.log(d.toJSON()) + // console.log(genericDelta.toJSON()) + // debugger + // const d2 = this.target.getDelta(am, whatToWatch) + // throw new Error('should match', d2) + // } + // return d } /** @@ -1117,12 +1130,12 @@ export class YText extends AbstractType { } } else { for (; item !== null && cs.length < 50; item = item.right) { - am.readContent(cs, item.id.client, item.id.clock, item.deleted, item.content, true) + am.readContent(cs, item.id.client, item.id.clock, item.deleted, item.content, !item.deleted) } } for (let i = 0; i < cs.length; i++) { const c = cs[i] - const renderDelete = c.deleted && c.attrs != null && c.render + const renderDelete = c.deleted && (c.attrs != null || c.render) const renderInsert = !c.deleted && (c.render || c.attrs != null) const attribution = (renderDelete || renderInsert) ? createAttributionFromAttributionItems(c.attrs, c.deleted).attribution : null switch (c.content.constructor) { @@ -1179,7 +1192,7 @@ export class YText extends AbstractType { changedAttributes[key] = value } } else if (renderDelete) { - if (equalAttrs(value,currAttrVal)) { + if (equalAttrs(value, currAttrVal)) { delete changedAttributes[key] delete currentAttributes[key] } else { diff --git a/src/utils/AttributionManager.js b/src/utils/AttributionManager.js index b266f26d..d8078485 100644 --- a/src/utils/AttributionManager.js +++ b/src/utils/AttributionManager.js @@ -326,7 +326,7 @@ export class SnapshotAttributionManager { if (s.attrs?.length === 0) { attrsWithoutChange = null } - contents.push(new AttributedContent(c, deleted, attrsWithoutChange, shouldRender)) + contents.push(new AttributedContent(c, deleted, attrsWithoutChange, !deleted)) } }) }