All files / roosterjs-content-model-dom/lib/modelApi/creators createSelectionMarker.ts

100% Statements 9/9
100% Branches 4/4
100% Functions 2/2
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 25 26 27 28 29 30 311x 1x                   1x     1911x   1911x 1291x 14201x 1639x         1911x            
import { EmptySegmentFormat } from '../../constants/EmptySegmentFormat';
import { getObjectKeys } from '../../domUtils/getObjectKeys';
import type {
    ContentModelSegmentFormat,
    ContentModelSelectionMarker,
} from 'roosterjs-content-model-types';
 
/**
 * Create a ContentModelSelectionMarker model
 * @param format @optional The format of this model
 */
export function createSelectionMarker(
    format?: Readonly<ContentModelSegmentFormat>
): ContentModelSelectionMarker {
    const filteredFormat: ContentModelSegmentFormat = {};
 
    if (format) {
        getObjectKeys(EmptySegmentFormat).forEach(key => {
            if (key in format) {
                (filteredFormat[key] as any) = format[key];
            }
        });
    }
 
    return {
        segmentType: 'SelectionMarker',
        isSelected: true,
        format: filteredFormat,
    };
}