selection-ranges

WebJar for selection-ranges

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

selection-ranges
Last Version

Last Version

3.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

selection-ranges
WebJar for selection-ranges
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/nikku/selection-ranges

Download selection-ranges

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/selection-ranges/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>selection-ranges</artifactId>
    <version>3.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/selection-ranges/
implementation 'org.webjars.npm:selection-ranges:3.0.3'
// https://jarcasting.com/artifacts/org.webjars.npm/selection-ranges/
implementation ("org.webjars.npm:selection-ranges:3.0.3")
'org.webjars.npm:selection-ranges:jar:3.0.3'
<dependency org="org.webjars.npm" name="selection-ranges" rev="3.0.3">
  <artifact name="selection-ranges" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='selection-ranges', version='3.0.3')
)
libraryDependencies += "org.webjars.npm" % "selection-ranges" % "3.0.3"
[org.webjars.npm/selection-ranges "3.0.3"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.npm : dom-iterator jar [1.0.0,2)

Project Modules

There are no modules declared in this project.

selection-ranges

Build Status

Manipulate selection ranges on contenteditable elements.

API

/**
 * 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);
/**
 * Selects the given range on the specified element.
 *
 * @param {Element} el
 * @param {Object} range {start, end}
 */
setRange(el, range);
/**
 * Return true if element is part of window selection.
 *
 * @param  {Element}  el
 * @return {Boolean}
 */
isSelected(el);

Usage

import {
  getRange,
  setRange
} from 'selection-ranges';


var node = <div contenteditable />;

let range = getRange(node);
// a range such as { start: 5, end: 10 }
// or null if node is currently not selected

setRange(node, { start: 0, end: 30 });
// sets selection range to child nodes; does not focus node

Features

  • Works around browser issues and correctly handles <br/> and paragraph elements
  • Correctly handles out-of-bounds selections

Related

  • selection-update - compute input selection updates on external content changes

License

MIT

Versions

Version
3.0.3