mirror of
https://github.com/yjs/yjs.git
synced 2025-12-16 03:37:50 +01:00
fuzz tests for unformatted text run
This commit is contained in:
@@ -34,6 +34,7 @@ import {
|
||||
|
||||
import * as delta from '../utils/Delta.js'
|
||||
|
||||
import * as math from 'lib0/math'
|
||||
import * as traits from 'lib0/traits'
|
||||
import * as object from 'lib0/object'
|
||||
import * as map from 'lib0/map'
|
||||
@@ -105,7 +106,7 @@ export class ItemTextListPosition {
|
||||
(length > 0 ||
|
||||
(
|
||||
negatedAttributes.size > 0 &&
|
||||
(this.right.deleted || this.right.content.constructor === ContentFormat)
|
||||
((this.right.deleted && this.am.contentLength(this.right) === 0) || this.right.content.constructor === ContentFormat)
|
||||
)
|
||||
)
|
||||
) {
|
||||
@@ -133,11 +134,28 @@ export class ItemTextListPosition {
|
||||
break
|
||||
}
|
||||
default: {
|
||||
const rightLen = this.am.contentLength(this.right)
|
||||
const item = this.right
|
||||
const rightLen = this.am.contentLength(item)
|
||||
if (length < rightLen) {
|
||||
getItemCleanStart(transaction, createID(this.right.id.client, this.right.id.clock + length))
|
||||
/**
|
||||
* @type {Array<import('../internals.js').AttributedContent<any>>}
|
||||
*/
|
||||
const contents = []
|
||||
this.am.readContent(contents, item.id.client, item.id.clock, item.deleted, item.content, 0)
|
||||
let i = 0
|
||||
for (; i < contents.length && length > 0; i++) {
|
||||
const c = contents[i]
|
||||
if ((!c.deleted || c.attrs != null) && c.content.isCountable()) {
|
||||
length -= c.content.getLength()
|
||||
}
|
||||
}
|
||||
if (length < 0 || (length === 0 && i !== contents.length)) {
|
||||
const c = contents[--i]
|
||||
getItemCleanStart(transaction, createID(item.id.client, c.clock + c.content.getLength() + length))
|
||||
}
|
||||
} else {
|
||||
length -= rightLen
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -554,16 +572,26 @@ const deleteText = (transaction, currPos, length) => {
|
||||
}
|
||||
} else if (currPos.am !== noAttributionsManager) {
|
||||
const item = currPos.right
|
||||
let d = currPos.am.contentLength(item)
|
||||
if (d > 0) {
|
||||
if (length < d) {
|
||||
getItemCleanStart(transaction, createID(currPos.right.id.client, currPos.right.id.clock + length))
|
||||
d = length
|
||||
}
|
||||
/**
|
||||
* @type {Array<import('../internals.js').AttributedContent<any>>}
|
||||
*/
|
||||
const contents = []
|
||||
currPos.am.readContent(contents, item.id.client, item.id.clock, true, item.content, 0)
|
||||
for (let i = 0; i < contents.length; i++) {
|
||||
const c = contents[i]
|
||||
if (c.content.isCountable() && c.attrs != null) {
|
||||
// deleting already deleted content. store that information in a meta property, but do
|
||||
// nothing
|
||||
map.setIfUndefined(transaction.meta, 'attributedDeletes', createIdSet).add(item.id.client, item.id.clock, d)
|
||||
length -= d
|
||||
const contentLen = math.min(c.content.getLength(), length)
|
||||
map.setIfUndefined(transaction.meta, 'attributedDeletes', createIdSet).add(item.id.client, c.clock, contentLen)
|
||||
length -= contentLen
|
||||
}
|
||||
}
|
||||
const lastContent = contents.length > 0 ? contents[contents.length - 1] : null
|
||||
const nextItemClock = item.id.clock + item.length
|
||||
const nextContentClock = lastContent != null ? lastContent.clock + lastContent.content.getLength() : nextItemClock
|
||||
if (nextContentClock < nextItemClock) {
|
||||
getItemCleanStart(transaction, createID(item.id.client, nextContentClock))
|
||||
}
|
||||
}
|
||||
currPos.forward()
|
||||
|
||||
@@ -89,12 +89,14 @@ export const createAttributionFromAttributionItems = (attrs, deleted) => {
|
||||
export class AttributedContent {
|
||||
/**
|
||||
* @param {AbstractContent} content
|
||||
* @param {number} clock
|
||||
* @param {boolean} deleted
|
||||
* @param {Array<import('./IdMap.js').AttributionItem<T>> | null} attrs
|
||||
* @param {0|1|2} renderBehavior
|
||||
*/
|
||||
constructor (content, deleted, attrs, renderBehavior) {
|
||||
constructor (content, clock, deleted, attrs, renderBehavior) {
|
||||
this.content = content
|
||||
this.clock = clock
|
||||
this.deleted = deleted
|
||||
this.attrs = attrs
|
||||
this.render = renderBehavior === 0 ? false : (renderBehavior === 1 ? (!deleted || attrs != null) : true)
|
||||
@@ -169,7 +171,7 @@ export class TwosetAttributionManager extends ObservableV2 {
|
||||
content = c.splice(s.len)
|
||||
}
|
||||
if (!deleted || s.attrs != null || shouldRender) {
|
||||
contents.push(new AttributedContent(c, deleted, s.attrs, shouldRender))
|
||||
contents.push(new AttributedContent(c, s.clock, deleted, s.attrs, shouldRender))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -200,14 +202,14 @@ export class NoAttributionsManager extends ObservableV2 {
|
||||
/**
|
||||
* @param {Array<AttributedContent<any>>} contents - where to write the result
|
||||
* @param {number} _client
|
||||
* @param {number} _clock
|
||||
* @param {number} clock
|
||||
* @param {boolean} deleted
|
||||
* @param {AbstractContent} content
|
||||
* @param {0|1|2} shouldRender - whether this should render or just result in a `retain` operation
|
||||
*/
|
||||
readContent (contents, _client, _clock, deleted, content, shouldRender) {
|
||||
readContent (contents, _client, clock, deleted, content, shouldRender) {
|
||||
if (!deleted || shouldRender) {
|
||||
contents.push(new AttributedContent(content, deleted, null, shouldRender))
|
||||
contents.push(new AttributedContent(content, clock, deleted, null, shouldRender))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,7 +364,7 @@ export class DiffAttributionManager extends ObservableV2 {
|
||||
}
|
||||
content = s.len < clen ? c.splice(s.len) : null
|
||||
if (shouldRender || !deleted || s.attrs != null) {
|
||||
contents.push(new AttributedContent(c, deleted, s.attrs, shouldRender))
|
||||
contents.push(new AttributedContent(c, s.clock, deleted, s.attrs, shouldRender))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -444,7 +446,7 @@ export class SnapshotAttributionManager extends ObservableV2 {
|
||||
if (s.attrs?.length === 0) {
|
||||
attrsWithoutChange = null
|
||||
}
|
||||
contents.push(new AttributedContent(c, deleted, attrsWithoutChange, shouldRender))
|
||||
contents.push(new AttributedContent(c, s.clock, deleted, attrsWithoutChange, shouldRender))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user