All files / roosterjs-content-model-dom/lib/modelToDom/utils cleanUpRestNodes.ts

100% Statements 9/9
100% Branches 4/4
100% Functions 1/1
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 251x                 1x 1068x 88x   88x 87x 78x     87x     88x      
import { isNodeOfType } from '../../domUtils/isNodeOfType';
import type { RewriteFromModel } from 'roosterjs-content-model-types';
 
/**
 * @internal
 * Cleans up all rest nodes starting from refNode
 * @param refNode The reference node to start cleaning up
 * @param rewriteContext The context for rewrite process
 */
export function cleanUpRestNodes(refNode: Node | null, rewriteContext: RewriteFromModel) {
    while (refNode) {
        const next = refNode.nextSibling;
 
        if (refNode.parentNode) {
            if (isNodeOfType(refNode, 'ELEMENT_NODE')) {
                rewriteContext.removedBlockElements.push(refNode);
            }
 
            refNode.parentNode.removeChild(refNode);
        }
 
        refNode = next;
    }
}