fix some edge cases

This commit is contained in:
Kevin Jahns
2025-05-19 00:50:34 +02:00
parent 4d582748c1
commit 7d5d6b840f
3 changed files with 23 additions and 10 deletions

View File

@@ -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<import('../internals.js').AttributedContent<any>>}
*/
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<import('../internals.js').AttributedContent<any>>}
*/
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))

View File

@@ -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 {

View File

@@ -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))
}
})
}