selection-ranges
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -9,2 +9,6 @@ # Changelog | ||
## 1.1.0 | ||
* `FEAT`: add `isSelected(el)` util | ||
## 1.0.1 | ||
@@ -11,0 +15,0 @@ |
32
index.js
@@ -37,2 +37,26 @@ 'use strict'; | ||
/** | ||
* Return true if element is part of window selection. | ||
* | ||
* @param {Element} el | ||
* @return {Boolean} | ||
*/ | ||
function isSelected(el) { | ||
if (!selection.rangeCount) { | ||
return null; | ||
} | ||
var focusNode = selection.focusNode; | ||
if (el !== focusNode && !el.contains(focusNode)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
module.exports.isSelected = isSelected; | ||
/** | ||
* Set cursor or selection position. | ||
@@ -60,12 +84,6 @@ * | ||
if (!selection.rangeCount) { | ||
if (!isSelected(el)) { | ||
return null; | ||
} | ||
var focusNode = selection.focusNode; | ||
if (el !== focusNode && !el.contains(focusNode)) { | ||
return null; | ||
} | ||
var range = selection.getRangeAt(0); | ||
@@ -72,0 +90,0 @@ |
{ | ||
"name": "selection-ranges", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Selection range manipulation for contenteditable elements", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,2 +8,36 @@ # selection-ranges | ||
## API | ||
```javascript | ||
/** | ||
* Return the selection on the given element as {start, end}. | ||
* | ||
* @param {Element} el | ||
* | ||
* @return {Object} selection range or null if element is not selected | ||
*/ | ||
getRange(el); | ||
``` | ||
```javascript | ||
/** | ||
* Selects the given range on the specified element. | ||
* | ||
* @param {Element} el | ||
* @param {Object} range {start, end} | ||
*/ | ||
setRange(el, range); | ||
``` | ||
```javascript | ||
/** | ||
* Return true if element is part of window selection. | ||
* | ||
* @param {Element} el | ||
* @return {Boolean} | ||
*/ | ||
isSelected(el); | ||
``` | ||
## Usage | ||
@@ -35,4 +69,9 @@ | ||
## Related | ||
* [selection-update](https://github.com/nikku/selection-update) - compute input selection updates on external content changes | ||
## License | ||
MIT |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8552
247
75