(transaction, currPos, length)
| 353 | * @function |
| 354 | */ |
| 355 | export const deleteText = (transaction, currPos, length) => { |
| 356 | const startLength = length |
| 357 | const startAttrs = map.copy(currPos.currentAttributes) |
| 358 | const start = currPos.right |
| 359 | while (length > 0 && currPos.right !== null) { |
| 360 | const item = currPos.right |
| 361 | if (!item.deleted && item.countable) { |
| 362 | if (length < item.length) { |
| 363 | getItemCleanStart(transaction, createID(item.id.client, item.id.clock + length)) |
| 364 | } |
| 365 | length -= item.length |
| 366 | item.delete(transaction) |
| 367 | } else if (currPos.am !== noAttributionsManager) { |
| 368 | /** |
| 369 | * @type {Array<import('./internals.js').AttributedContent<any>>} |
| 370 | */ |
| 371 | const contents = [] |
| 372 | currPos.am.readContent(contents, item.id.client, item.id.clock, true, item.content, 0) |
| 373 | for (let i = 0; i < contents.length; i++) { |
| 374 | const c = contents[i] |
| 375 | if (c.content.isCountable() && c.attrs != null) { |
| 376 | // deleting already deleted content. store that information in a meta property, but do |
| 377 | // nothing |
| 378 | const contentLen = math.min(c.content.getLength(), length) |
| 379 | map.setIfUndefined(transaction.meta, 'attributedDeletes', createIdSet).add(item.id.client, c.clock, contentLen) |
| 380 | length -= contentLen |
| 381 | } |
| 382 | } |
| 383 | const lastContent = contents.length > 0 ? contents[contents.length - 1] : null |
| 384 | const nextItemClock = item.id.clock + item.length |
| 385 | const nextContentClock = lastContent != null ? lastContent.clock + lastContent.content.getLength() : nextItemClock |
| 386 | if (nextContentClock < nextItemClock) { |
| 387 | getItemCleanStart(transaction, createID(item.id.client, nextContentClock)) |
| 388 | } |
| 389 | } |
| 390 | currPos.forward() |
| 391 | } |
| 392 | if (start) { |
| 393 | cleanupFormattingGap(transaction, start, currPos.right, startAttrs, currPos.currentAttributes) |
| 394 | } |
| 395 | const parent = /** @type {YType<any>} */ (/** @type {Item} */ (currPos.left || currPos.right).parent) |
| 396 | if (parent._searchMarker) { |
| 397 | updateMarkerChanges(parent._searchMarker, currPos.index, -startLength + length) |
| 398 | } |
| 399 | return currPos |
| 400 | } |
| 401 | |
| 402 | export class ArraySearchMarker { |
| 403 | /** |
no test coverage detected
searching dependent graphs…