Range

API reference for ranges in Slate.

A Range is a set of points that refer to a specific span of a Slate document. They can define a span inside a single node or span across multiple nodes. A range consists of two points: an anchor (start) and a focus (end).

type TRange = {
  anchor: Point
  focus: Point
}

RangeAPI

transform

Transform a range by an operation.

Parameters

Collapse all

    The range to transform.

    The operation to apply to the range.

    Options for transforming the range.

OptionsRangeTransformOptions

Collapse all

    The direction to prefer when transforming the range.

ReturnsTRange | null

    The transformed range, or null if the range was deleted.

edges

Get the start and end points of a range.

Parameters

Collapse all

    The range to get edges from.

    Options for retrieving edges.

OptionsRangeEdgesOptions

Collapse all

    If true, returns points in reverse order.

Returns[Point, Point]

    A tuple of points representing the start and end points.

end

Get the end point of a range.

Parameters

Collapse all

    The range to get the end point from.

ReturnsPoint

    The end point of the range.

equals

Check if two ranges are exactly equal.

Parameters

Collapse all

    The first range to compare.

    The second range to compare.

Returnsboolean

    true if the ranges are exactly equal.

includes

Check if a range includes a path, point, or part of another range.

Parameters

Collapse all

    The range to check.

    The target to check for inclusion.

Returnsboolean

    true if the range includes the target.

intersection

Get the intersection of two ranges.

Parameters

Collapse all

    The first range.

    The second range.

ReturnsTRange | null

    The intersecting range, or null if there is no intersection.

isBackward

Check if a range is backward (anchor point appears after focus point).

Parameters

Collapse all

    The range to check.

Returnsboolean

    true if the range is backward.

isCollapsed

Check if a range is collapsed (both points refer to the same position).

Parameters

Collapse all

    The range to check.

Returnsboolean

    true if the range exists and is collapsed.

isExpanded

Check if a range is expanded (not collapsed).

Parameters

Collapse all

    The range to check.

Returnsboolean

    true if the range exists and is expanded.

isForward

Check if a range is forward (anchor point appears before focus point).

Parameters

Collapse all

    The range to check.

Returnsboolean

    true if the range is forward.

isRange

Check if a value implements the TRange interface.

Parameters

Collapse all

    The value to check.

Returnsboolean

    true if the value is a range.

points

Iterate through all point entries in a range.

Parameters

Collapse all

    The range to iterate through.

ReturnsGenerator<PointEntry, void, undefined>

    A generator that yields point entries.

start

Get the start point of a range.

Parameters

Collapse all

    The range to get the start point from.

ReturnsPoint

    The start point of the range.

surrounds

Check if a range completely surrounds another range.

Parameters

Collapse all

    The range that might surround the target.

    The target range that might be surrounded.

Returnsboolean

    true if the range surrounds the target.

Types

TRange

TRange objects are a set of points that refer to a specific span of a Slate document. They can define a span inside a single node or span across multiple nodes.

Range is a type alias for TRange.

Attributes

Collapse all

    The start point of the range.

    The end point of the range.