@gechiui/dom
Version:
DOM utilities module for GeChiUI.
32 lines (28 loc) • 1.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = documentHasTextSelection;
var _assertIsDefined = require("../utils/assert-is-defined");
/**
* Internal dependencies
*/
/**
* Check whether the current document has selected text. This applies to ranges
* of text in the document, and not selection inside `<input>` and `<textarea>`
* elements.
*
* See: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects.
*
* @param {Document} doc The document to check.
*
* @return {boolean} True if there is selection, false if not.
*/
function documentHasTextSelection(doc) {
(0, _assertIsDefined.assertIsDefined)(doc.defaultView, 'doc.defaultView');
const selection = doc.defaultView.getSelection();
(0, _assertIsDefined.assertIsDefined)(selection, 'selection');
const range = selection.rangeCount ? selection.getRangeAt(0) : null;
return !!range && !range.collapsed;
}
//# sourceMappingURL=document-has-text-selection.js.map