MCPcopy
hub / github.com/yjs/yjs / cleanupYTextFormatting

Function cleanupYTextFormatting

src/utils/Transaction.js:425–450  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

423 * @return {number} How many formatting attributes have been cleaned up.
424 */
425export const cleanupYTextFormatting = type => {
426 if (!type.doc?.cleanupFormatting) return 0
427 let res = 0
428 transact(/** @type {Doc} */ (type.doc), transaction => {
429 let start = /** @type {Item} */ (type._start)
430 let end = type._start
431 let startAttributes = map.create()
432 const currentAttributes = map.copy(startAttributes)
433 while (end) {
434 if (end.deleted === false) {
435 switch (end.content.constructor) {
436 case ContentFormat:
437 updateCurrentAttributes(currentAttributes, /** @type {ContentFormat} */ (end.content))
438 break
439 default:
440 res += cleanupFormattingGap(transaction, start, end, startAttributes, currentAttributes)
441 startAttributes = map.copy(currentAttributes)
442 start = end
443 break
444 }
445 }
446 end = end.right
447 }
448 })
449 return res
450}
451
452/**
453 * This will be called by the transaction once the event handlers are called to potentially cleanup

Callers 1

Calls 4

transactFunction · 0.85
cleanupFormattingGapFunction · 0.85
updateCurrentAttributesFunction · 0.70
copyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…