SelectionModelA class representing a selection range in text.
startThe starting position of the selection.
endThe end position of the selection.
previousThe selection range from before the last update.
constructor(pos?: number)Initializes a new instance of the SelectionModel class with a given position.
pos - The position to set the start and end of the selection to.constructor(range?: SelectionRange)Initializes a new instance of the SelectionModel class with a given range.
range - The range to set the start and end of the selection to.constructor(selection?: SelectionModel)Initializes a new instance of the SelectionModel class with a given selection.
selection - The selection to set the start and end of this selection to.direction: SelectionDirectionGets the direction of the selection. Returns a value of type SelectionDirection.
size: numberGets sie of the selection, that is the absolute difference between start and end position of the selection.
isInSelectionisInSelection(pos: number): boolean
Determines whether a given position is inside of the selection.
pos - The position to check.isBeforeSelectionisBeforeSelection(pos: number): boolean
Determines whether a given position is before the selection.
pos - The position to check.isAfterSelectionisAfterSelection(pos: number): boolean
Determines whether a given position is after the selection.
pos - The position to check.getget(): SelectionRange<number>
Gets the range of the selection.
getOrderedgetOrdered(): 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.
getPreviousgetPrevious(): SelectionRange<number>
Gets the range of the selection from before the last update.
setset(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.
number value is provided, the start and end values of the selection are both set to the provided value.SelectionRange value is provided, the start and end values of the selection are set to the start and end values of the provided range, respectively.If a direction is provided, the new selection start & end values are swapped if direction is set "backward". Otherwise, nothing is changed.
expandexpand(pos: number): void;
expand(range: SelectionRange<number>): void;
Expands the selection range up to the provided position or range.
number value is provided, the start and end values of the selection are both expanded to the provided value.SelectionRange value is provided, the start and end values of the selection are expanded to the start and end values of the provided range, respectively.setEndsetEnd(pos: number): void
Sets the end position of the selection.
pos - The end position to set the selection to.offsetoffset(pos: number): void;
offset(range: SelectionRange<number>): void;
Offsets the selection range by the provided position or range.
number value is provided, both the start and end values of the selection are increased by the provided value.SelectionRange value is provided, the start and end values of the selection are increased by the start and end values of the provided range, respectively.save and restoresave(): 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.