All files / roosterjs-content-model-dom/lib/formatHandlers/block whiteSpaceFormatHandler.ts

100% Statements 8/8
87.5% Branches 7/8
100% Functions 2/2
100% Lines 8/8

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 231x             1x   1377x   1377x 130x       1153x 1153x 93x        
import { shouldSetValue } from '../utils/shouldSetValue';
import type { FormatHandler } from '../FormatHandler';
import type { WhiteSpaceFormat } from 'roosterjs-content-model-types';
 
/**
 * @internal
 */
export const whiteSpaceFormatHandler: FormatHandler<WhiteSpaceFormat> = {
    parse: (format, element, _, defaultStyle) => {
        const whiteSpace = element.style.whiteSpace || defaultStyle.whiteSpace;
 
        if (shouldSetValue(whiteSpace, 'normal', format.whiteSpace, defaultStyle.whiteSpace)) {
            format.whiteSpace = whiteSpace;
        }
    },
    apply: (format, element, context) => {
        const whiteSpace = context.implicitFormat.whiteSpace;
        if (format.whiteSpace != whiteSpace) {
            element.style.whiteSpace = format.whiteSpace || 'normal';
        }
    },
};