input-selection-model

SelectionModel

A class representing a selection range in text.

Properties

start

The starting position of the selection.

end

The end position of the selection.

previous

The selection range from before the last update.

Constructors

constructor(pos?: number)

Initializes a new instance of the SelectionModel class with a given position.

constructor(range?: SelectionRange)

Initializes a new instance of the SelectionModel class with a given range.

constructor(selection?: SelectionModel)

Initializes a new instance of the SelectionModel class with a given selection.

Getters

direction: SelectionDirection

Gets the direction of the selection. Returns a value of type SelectionDirection.

size: number

Gets sie of the selection, that is the absolute difference between start and end position of the selection.

Methods

isInSelection

isInSelection(pos: number): boolean

Determines whether a given position is inside of the selection.

isBeforeSelection

isBeforeSelection(pos: number): boolean

Determines whether a given position is before the selection.

isAfterSelection

isAfterSelection(pos: number): boolean

Determines whether a given position is after the selection.

get

get(): SelectionRange<number>

Gets the range of the selection.

getOrdered

getOrdered(): SelectionRange<number>

Gets the ordered selection range.

The ordered selection range has the smaller number as the start position, and the larger number as the end position.

getPrevious

getPrevious(): SelectionRange<number>

Gets the range of the selection from before the last update.

set

set(pos: number): void;
set(range: SelectionRange<number>): void;
set(range: SelectionRange<number>, direction: SelectionDirection): void;

Sets the selection range to the provided value, following the direction, if provided.

If a direction is provided, the new selection start & end values are swapped if direction is set "backward". Otherwise, nothing is changed.

expand

expand(pos: number): void;
expand(range: SelectionRange<number>): void;

Expands the selection range up to the provided position or range.

setEnd

setEnd(pos: number): void

Sets the end position of the selection.

offset

offset(pos: number): void;
offset(range: SelectionRange<number>): void;

Offsets the selection range by the provided position or range.

save and restore

save(): void;
restore(): void;

Methods for saving and later restoring the current state of the selection.

If the restore method is called, but the selection was never saved before, nothing happens.