All files / roosterjs-content-model-plugins/lib/findReplace/utils setMarkedIndex.ts

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

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 34 35 36 37 38 39 40 41 42 431x             1x           2x 2x   2x   2x 1x 1x   1x 1x                   1x     2x            
import { scrollRectIntoView } from 'roosterjs-content-model-dom';
import type { IEditor, Rect } from 'roosterjs-content-model-types';
import type { FindReplaceContext } from '../types/FindReplaceContext';
 
/**
 * @internal
 */
export function setMarkedIndex(
    editor: IEditor,
    context: FindReplaceContext,
    index: number,
    alternativeRange?: Range | null
): void {
    context.replaceHighlight.clear();
    context.markedIndex = index;
 
    const range = context.ranges[context.markedIndex];
 
    if (range) {
        context.replaceHighlight.addRanges([range]);
        let rect: Rect | null;
 
        Eif (context.scrollMargin >= 0 && (rect = editor.getVisibleViewport())) {
            scrollRectIntoView(
                editor.getScrollContainer(),
                rect,
                editor.getDOMHelper(),
                range.getBoundingClientRect(),
                context.scrollMargin,
                true /*preferTop*/
            );
        }
    } else {
        context.markedIndex = -1;
    }
 
    editor.triggerEvent('findResultChanged', {
        markedIndex: context.markedIndex,
        ranges: context.ranges,
        alternativeRange,
    });
}