Expand all

ve.Range

Constructor

new ve.Range([from], [to]) #

Parameters:

Name Type Attributes Default Description
from number optional
0

Anchor offset

to number optional
from

Focus offset

Source:

Methods

containsOffset(offset) → {boolean} #

Check if an offset is within the range.

Specifically we mean the whole element at a specific offset, so in effect this is the same as #containsRange( new ve.Range( offset, offset + 1 ) ).

Parameters:

Name Type Description
offset number

Offset to check

Source:

Returns:

If offset is within the range

Type
boolean
Check if an offset is within the range.

containsRange(range) → {boolean} #

Check if another range is within the range.

Parameters:

Name Type Description
range ve.Range

Range to check

Source:

Returns:

If other range is within the range

Type
boolean
Check if another range is within the range.

equals(other) → {boolean} #

Check if two ranges are equal, taking direction into account.

Parameters:

Name Type Description
other ve.Range | null
Source:

Returns:

Type
boolean
Check if two ranges are equal, taking direction into account.

equalsSelection(other) → {boolean} #

Check if two ranges are equal, ignoring direction.

Parameters:

Name Type Description
other ve.Range | null
Source:

Returns:

Type
boolean
Check if two ranges are equal, ignoring direction.

expand(other) → {ve.Range} #

Expand a range to include another range, preserving direction.

Parameters:

Name Type Description
other ve.Range

Range to expand to include

Source:

Returns:

Range covering this range and other

Type
ve.Range
Expand a range to include another range, preserving direction.

flip() → {ve.Range} #

Gets a range with reversed direction.

Source:

Returns:

A new range

Type
ve.Range
Gets a range with reversed direction.

getLength() → {number} #

Get the length of the range.

Source:

Returns:

Length of range

Type
number
Get the length of the range.

isBackwards() → {boolean} #

Check if the range is backwards, i.e. from > to

Source:

Returns:

Range is backwards

Type
boolean
Check if the range is backwards, i.e.

isCollapsed() → {boolean} #

Check if the range is collapsed.

A collapsed range has equal start and end values making its length zero.

Source:

Returns:

Range is collapsed

Type
boolean
Check if the range is collapsed.

overlapsRange(range) → {boolean} #

Check if another range overlaps this one

This includes ranges which intersect this one, e.g. [1,3] & [2,4], and ranges which cover this one completely, e.g. [1,3] & [0,5], but not ranges which only touch, e.g. [0,2] & [2,4].

Parameters:

Name Type Description
range ve.Range

Range to check

Source:

Returns:

If other range overlaps this range

Type
boolean

Check if another range overlaps this one

This includes ranges which intersect this one, e.g.

toJSON([key]) → {Object} #

Get a object summarizing the range for JSON serialization

Parameters:

Name Type Attributes Description
key string optional

Key in parent object

Source:

Returns:

Object for JSON serialization

Type
Object
Get a object summarizing the range for JSON serialization

touchesRange(range) → {boolean} #

Check if another range is touching this one

This includes ranges which touch this one, e.g. [1,3] & [3,5], ranges which overlap this one, and ranges which cover this one completely, e.g. [1,3] & [0,5].

Useful for testing if two ranges can be joined (using #expand)

Parameters:

Name Type Description
range ve.Range

Range to check

Source:

Returns:

If other range touches this range

Type
boolean

Check if another range is touching this one

This includes ranges which touch this one, e.g.

translate(distance) → {ve.Range} #

Get a range that's a translated version of this one.

Parameters:

Name Type Description
distance number

Distance to move range by

Source:

Returns:

New translated range

Type
ve.Range
Get a range that's a translated version of this one.

truncate(limit) → {ve.Range} #

Create a new range with a truncated length.

Parameters:

Name Type Description
limit number

Maximum length of new range (negative for left-side truncation)

Source:

Returns:

A new range

Type
ve.Range
Create a new range with a truncated length.

newCoveringRange(ranges, backwards) → {ve.Range}static #

Create a range object that covers all of the given ranges.

Parameters:

Name Type Description
ranges Array.<ve.Range>

Array of ve.Range objects (at least one)

backwards boolean

Return a backwards range

Source:

Returns:

Range that spans all of the given ranges

Type
ve.Range
Create a range object that covers all of the given ranges.

newFromHash(hash) → {ve.Range}static #

Create a new range from a range hash object

Parameters:

Name Type Description
hash Object
Source:
See:

Returns:

New range

Type
ve.Range
Create a new range from a range hash object

newFromJSON(json) → {ve.Range}static #

Create a new range from a JSON serialization of a range

Parameters:

Name Type Description
json string

JSON serialization

Source:
See:

Returns:

New range

Type
ve.Range
Create a new range from a JSON serialization of a range