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
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
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
equalsSelection(other) → {boolean}
#
Check if two ranges are equal, ignoring direction.
Parameters:
| Name | Type | Description |
|---|---|---|
other |
ve.Range
|
null
|
- Source:
Returns:
- Type
- boolean
every(callback) → {boolean}
#
Test whether all indices in the range pass the test implemented by the provided function.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function | Function called for each index |
- Source:
Returns:
True if the callback returns true for all indices
- Type
- boolean
expand(other) → {ve.Range}
#
expandCallback(callback, maxRange) → {ve.Range}
#
Expand the range outwards from both ends while callback returns true. Walks from start-1 backwards and end forwards, expanding as long as callback returns true. Stops expanding at each end when callback returns false. Returns a new expanded range.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function | Called with (index, iFromStartOrEnd) |
maxRange |
ve.Range | Maximum range to expand to |
- Source:
Returns:
New expanded range
- Type
- ve.Range
flip() → {ve.Range}
#
forEach(callback)
#
Iterate over the range, calling a function for each index
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function | Function called for each index |
- Source:
getLength() → {number}
#
isBackwards() → {boolean}
#
Check if the range is backwards, i.e. from > to
- Source:
Returns:
Range is backwards
- Type
- boolean
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
map(callback) → {Array}
#
Iterate over the range, calling a function for each index, to build an array.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function | Function called for each index |
- Source:
Returns:
Array of results
- Type
- Array
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.
some(callback) → {boolean}
#
Test whether at least one index in the range passes the test implemented by the provided function.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function | Function called for each index |
- Source:
Returns:
True if the callback returns true for any index
- Type
- boolean
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
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
trimCallback(callback) → {ve.Range}
#
Trim elements from both ends of the range using a callback.
Walks from start forwards and end backwards, removing elements for which callback returns true. Stops trimming at each end when callback returns false. Returns a new trimmed range.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function | Called with index |
- Source:
Returns:
New trimmed range
- Type
- ve.Range
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