Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

selection-ranges

Package Overview
Dependencies
Maintainers
0
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

selection-ranges

Selection range manipulation for contenteditable elements

  • 4.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8K
decreased by-3.08%
Maintainers
0
Weekly downloads
 
Created
Source

selection-ranges

CI

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

License

MIT

Keywords

FAQs

Package last updated on 15 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc