Skip to content

Type Editor


Type Editor / @type-editor/dom-util / text-range / textRange

Function: textRange()

ts
function textRange(node, from?, to?): Range;

Defined in: text-range.ts:22

Creates or reuses a DOM Range for a text node.

Note: This function always returns the same Range object for performance reasons. DOM Range objects are expensive to create and can slow down subsequent DOM updates. Call clearReusedRange() if you need to ensure the range is properly released.

Parameters

ParameterTypeDescription
nodeTextThe text node to create a range for
from?numberThe starting offset within the text node (defaults to 0)
to?numberThe ending offset within the text node (defaults to node length)

Returns

Range

A DOM Range object spanning the specified text range

Example

typescript
const textNode = document.createTextNode("Hello World");
const range = textRange(textNode, 0, 5); // Selects "Hello"