UNPKG

@onesy/utils

Version:
27 lines (26 loc) 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const clearSelection = (end = true) => { var _a; if (window.getSelection) { const selection = window.getSelection(); if (!selection) return; const previousRange = selection.getRangeAt(0); const newRange = window.document.createRange(); if (window.getSelection) { if (window.getSelection().empty) window.getSelection().empty(); else if (window.getSelection().removeAllRanges) window.getSelection().removeAllRanges(); } else if (window.document.selection) window.document.selection.empty(); if (end) { newRange.setStart(previousRange.endContainer, previousRange.endOffset); newRange.setEnd(previousRange.endContainer, previousRange.endOffset); (_a = (window.getSelection())) === null || _a === void 0 ? void 0 : _a.addRange(newRange); } } }; exports.default = clearSelection;