All files / roosterjs-content-model-plugins/lib/edit/inputSteps handleAutoLink.ts

90% Statements 9/10
73.33% Branches 11/15
100% Functions 1/1
88.89% Lines 8/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 281x           1x 52x   26x 52x 26x 26x   26x                          
import { promoteLink } from 'roosterjs-content-model-api';
import type { DeleteSelectionStep } from 'roosterjs-content-model-types';
 
/**
 * @internal
 */
export const handleAutoLink: DeleteSelectionStep = context => {
    const { deleteResult, insertPoint } = context;
 
    Eif (deleteResult == 'notDeleted' || deleteResult == 'nothingToDelete') {
        const { marker, paragraph } = insertPoint;
        const index = paragraph.segments.indexOf(marker);
        const segBefore = index > 0 ? paragraph.segments[index - 1] : null;
 
        Iif (
            segBefore?.segmentType == 'Text' &&
            promoteLink(segBefore, paragraph, {
                autoLink: true,
            }) &&
            context.formatContext
        ) {
            context.formatContext.canUndoByBackspace = true;
        }
 
        // Do not set deleteResult here since we haven't really start a new paragraph, we need other delete step to keep working on it
    }
};