| 423 | * @return {number} How many formatting attributes have been cleaned up. |
| 424 | */ |
| 425 | export 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 |
no test coverage detected
searching dependent graphs…