Skip to main content

Class: Range

libs/common/types/Range.Range

Hierarchy

Constructors

constructor

new Range(start, end)

Create a new range from two positions. If start is not before or equal to end, the values will be swapped.

Parameters

NameTypeDescription
startPositionA position.
endPositionA position.

Defined in

libs/common/types/Range.ts:21

new Range(startLine, startCharacter, endLine, endCharacter)

Create a new range from number coordinates. It is a shorter equivalent of using new Range(new Position(startLine, startCharacter), new Position(endLine, endCharacter))

Parameters

NameTypeDescription
startLinenumberA zero-based line value.
startCharacternumberA zero-based character value.
endLinenumberA zero-based line value.
endCharacternumberA zero-based character value.

Defined in

libs/common/types/Range.ts:32

Properties

end

Readonly end: Position

The end position. It is after or equal to start.

Defined in

libs/common/types/Range.ts:12


start

Readonly start: Position

The start position. It is before or equal to end.

Defined in

libs/common/types/Range.ts:7

Accessors

isEmpty

get isEmpty(): boolean

true if start and end are equal.

Returns

boolean

Defined in

libs/common/types/Range.ts:63


isSingleLine

get isSingleLine(): boolean

true if start.line and end.line are equal.

Returns

boolean

Defined in

libs/common/types/Range.ts:70

Methods

contains

contains(positionOrRange): boolean

Check if a position or a range is contained in this range.

Parameters

NameTypeDescription
positionOrRangeRange | PositionA position or a range.

Returns

boolean

true if the position or range is inside or equal to this range.

Defined in

libs/common/types/Range.ts:92


intersection

intersection(other): undefined | Range

Intersect range with this range and returns a new range or undefined if the ranges have no overlap.

Parameters

NameTypeDescription
otherRangeA range.

Returns

undefined | Range

A range of the greater start and smaller end positions. Will return undefined when there is no overlap.

Defined in

libs/common/types/Range.ts:108


isRangeEqual

isRangeEqual(other): boolean

Check if other equals this range.

Parameters

NameTypeDescription
otherRangeA range.

Returns

boolean

true when start and end are equal to start and end of this range.

Defined in

libs/common/types/Range.ts:81


toSelection

toSelection(isReversed): Selection

Construct a new selection from this range

Parameters

NameTypeDescription
isReversedbooleanIf true active is before anchor

Returns

Selection

A new selection

Defined in

libs/common/types/Range.ts:144


union

union(other): Range

Compute the union of other with this range.

Parameters

NameTypeDescription
otherRangeA range.

Returns

Range

A range of smaller start position and the greater end position.

Defined in

libs/common/types/Range.ts:120


with

with(start?, end?): Range

Derived a new range from this range.

Parameters

NameTypeDescription
start?PositionA position that should be used as start. The default value is the current start.
end?PositionA position that should be used as end. The default value is the current end.

Returns

Range

A range derived from this range with the given start and end position. If start and end are not different this range will be returned.

Defined in

libs/common/types/Range.ts:135