All files / roosterjs-content-model-plugins/lib/imageEdit/utils getSelectedImage.ts

100% Statements 6/6
100% Branches 5/5
100% Functions 1/1
100% Lines 6/6

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 201x             1x 12x   12x 8x         4x      
import { getSelectedSegmentsAndParagraphs } from 'roosterjs-content-model-dom';
import type { ReadonlyContentModelDocument } from 'roosterjs-content-model-types';
import type { ImageAndParagraph } from '../types/ImageAndParagraph';
 
/**
 * @internal
 */
export function getSelectedImage(model: ReadonlyContentModelDocument): ImageAndParagraph | null {
    const selections = getSelectedSegmentsAndParagraphs(model, false);
 
    if (selections.length == 1 && selections[0][0].segmentType == 'Image' && selections[0][1]) {
        return {
            image: selections[0][0],
            paragraph: selections[0][1],
        };
    } else {
        return null;
    }
}