All files / roosterjs-content-model-core/lib/corePlugin/entity findAllEntities.ts

100% Statements 18/18
100% Branches 6/6
100% Functions 5/5
100% Lines 17/17

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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45          1x 365x 368x   9x 9x     11x       11x     309x 387x   6x       6x     1x 1x     309x     39x 229x   39x        
import type { ChangedEntity, ReadonlyContentModelBlockGroup } from 'roosterjs-content-model-types';
 
/**
 * @internal
 */
export function findAllEntities(group: ReadonlyContentModelBlockGroup, entities: ChangedEntity[]) {
    group.blocks.forEach(block => {
        switch (block.blockType) {
            case 'BlockGroup':
                findAllEntities(block, entities);
                break;
 
            case 'Entity':
                entities.push({
                    entity: block,
                    operation: 'newEntity',
                });
                break;
 
            case 'Paragraph':
                block.segments.forEach(segment => {
                    switch (segment.segmentType) {
                        case 'Entity':
                            entities.push({
                                entity: segment,
                                operation: 'newEntity',
                            });
                            break;
 
                        case 'General':
                            findAllEntities(segment, entities);
                            break;
                    }
                });
                break;
 
            case 'Table':
                block.rows.forEach(row =>
                    row.cells.forEach(cell => findAllEntities(cell, entities))
                );
                break;
        }
    });
}