Range

API reference for ranges in Slate.

Range 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. A range consists of two points: an anchor (start) and a focus (end).

Range

Find the corresponding documentation in the Slate docs.

transform

Transforms a range by an operation.

Parameters

Collapse all

    The range to transform.

    The operation to apply to the range.

Returns

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

edges

Gets the start and end points of a range, in the order in which they appear in the document.

Parameters

Collapse all

    The range to get edges from.

Returns

    Returns a tuple of [Point, Point] representing the start and end points.

end

Gets the end point of a range.

Parameters

Collapse all

    The range to get the end point from.

Returns

    Returns the end point of the range.

equals

Checks if a range is exactly equal to another.

Parameters

Collapse all

    The first range to compare.

    The second range to compare.

Returns

    Returns true if the ranges are equal, false otherwise.

includes

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

Parameters

Collapse all

    The range to check.

    The target to check for inclusion.

Returns

    Returns true if the range includes the target, false otherwise.

intersection

Gets the intersection of a range with another.

Parameters

Collapse all

    The first range.

    The second range.

Returns

    Returns the intersecting range, or null if there is no intersection.

isBackward

Checks if a range is backward, meaning that its anchor point appears in the document after its focus point.

Parameters

Collapse all

    The range to check.

Returns

    Returns true if the range is backward, false otherwise.

isCollapsed

Checks if a range is collapsed, meaning that both its anchor and focus points refer to the exact same position in the document.

Parameters

Collapse all

    The range to check.

Returns

    Returns true if the range exists and is collapsed, false otherwise.

isExpanded

Checks if a range is expanded. This is the opposite of isCollapsed and is provided for legibility.

Parameters

Collapse all

    The range to check.

Returns

    Returns true if the range exists and is expanded, false otherwise.

isForward

Checks if a range is forward. This is the opposite of isBackward and is provided for legibility.

Parameters

Collapse all

    The range to check.

Returns

    Returns true if the range is forward, false otherwise.

isRange

Checks if a value implements the TRange interface.

Parameters

Collapse all

    The value to check.

Returns

    Returns true if the value is a range, false otherwise.

points

Iterates through all of the point entries in a range.

Parameters

Collapse all

    The range to iterate through.

Returns

    Returns a generator that yields point entries.

start

Gets the start point of a range.

Parameters

Collapse all

    The range to get the start point from.

Returns

    Returns the start point of the range.

surrounds

Checks if a range completely includes another range.

Parameters

Collapse all

    The range that might surround the target.

    The target range that might be surrounded.

Returns

    Returns true if the range surrounds the target, false otherwise.

Types

TRange

The base range type that represents a span in a Slate document.

Attributes

Collapse all

    The start point of the range.

    The end point of the range.

RangeEdgesOptions

Options for getting the edges of a range.

Attributes

Collapse all

    If true, returns the points in reverse order.

RangeTransformOptions

Options for transforming a range.

Attributes

Collapse all

    The direction to prefer when transforming the range.