All files / roosterjs-content-model-plugins/lib/edit/deleteSteps deleteList.ts

94.44% Statements 17/18
88.89% Branches 16/18
100% Functions 1/1
92.86% Lines 13/14

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 341x           1x 9x       9x   9x 8x         8x 8x   8x 6x 3x   3x     6x        
import { getClosestAncestorBlockGroupIndex } from 'roosterjs-content-model-dom';
import type { DeleteSelectionStep, ContentModelListItem } from 'roosterjs-content-model-types';
 
/**
 * @internal
 */
export const deleteList: DeleteSelectionStep = context => {
    Iif (context.deleteResult != 'notDeleted') {
        return;
    }
 
    const { paragraph, marker, path } = context.insertPoint;
 
    if (paragraph.segments[0] == marker) {
        const index = getClosestAncestorBlockGroupIndex<ContentModelListItem>(
            path,
            ['ListItem'],
            ['TableCell', 'FormatContainer']
        );
        const item = path[index] as ContentModelListItem | undefined;
        const lastLevel = item?.levels[item.levels.length - 1];
 
        if (lastLevel && item?.blocks[0] == paragraph) {
            if (lastLevel.format.displayForDummyItem == 'block') {
                item.levels.pop();
            } else {
                lastLevel.format.displayForDummyItem = 'block';
            }
 
            context.deleteResult = 'range';
        }
    }
};