MCPcopy
hub / github.com/yjs/yjs / deleteText

Function deleteText

src/ytype.js:355–400  ·  view source on GitHub ↗
(transaction, currPos, length)

Source from the content-addressed store, hash-verified

353 * @function
354 */
355export 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
402export class ArraySearchMarker {
403 /**

Callers 1

applyDeltaMethod · 0.85

Calls 11

getItemCleanStartFunction · 0.90
createIDFunction · 0.90
cleanupFormattingGapFunction · 0.90
updateMarkerChangesFunction · 0.85
forwardMethod · 0.80
copyMethod · 0.45
deleteMethod · 0.45
readContentMethod · 0.45
isCountableMethod · 0.45
getLengthMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…