"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.saveSelection = void 0;
/**
 * Save the current browser selection, so that it can be restored later. Returns
 * a callback to restore the selection.
 *
 * @returns Callback to restore the selection.
 */
const saveSelection = () => {
    const selection = window?.getSelection();
    if (!selection)
        return;
    const ranges = [];
    for (let i = 0; i < selection.rangeCount; i++)
        ranges.push(selection.getRangeAt(i));
    return () => {
        selection.removeAllRanges();
        for (const range of ranges)
            selection.addRange(range);
    };
};
exports.saveSelection = saveSelection;
//# sourceMappingURL=dom.js.map