All files / roosterjs-content-model-core/lib/corePlugin/copyPaste/utils adjustImageSelectionOnSafari.ts

100% Statements 6/6
87.5% Branches 7/8
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            1x 12x 1x 1x 1x 1x              
import type { IEditor, DOMSelection } from 'roosterjs-content-model-types';
 
/**
 * @internal
 * Adjust Image selection, so the copy by keyboard does not remove image selection.
 */
export function adjustImageSelectionOnSafari(editor: IEditor, selection: DOMSelection | null) {
    if (editor.getEnvironment().isSafari && selection?.type == 'image') {
        const range = new Range();
        range.setStartBefore(selection.image);
        range.setEndAfter(selection.image);
        editor.setDOMSelection({
            range,
            type: 'range',
            isReverted: false,
        });
    }
}