@onesy/utils
Version:
18 lines (17 loc) • 755 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const startSelection = (element, start = undefined, end = undefined) => {
var _a;
if (window.getSelection) {
const newRange = window.document.createRange();
const position = (_a = element === null || element === void 0 ? void 0 : element.childNodes) === null || _a === void 0 ? void 0 : _a.length;
newRange.setStart(element, start !== undefined ? start : position);
newRange.setEnd(element, end !== undefined ? end : position);
const selection = window.getSelection();
if (selection) {
selection.removeAllRanges();
selection.addRange(newRange);
}
}
};
exports.default = startSelection;
;