RichEditSelection Class

Contains a set of methods and properties to work with the document selection.

Declaration

export class RichEditSelection

Remarks

An instance of the RichEditSelection object can be accessed by the selection property.

Properties

active Property

Gets a cursor position.

Declaration

readonly active: number

Property Value

Type Description
number

The active selection position (the cursor position).

Remarks

Users can make a selection from left to right or from right to left. Use the anchor property to get the position where a user starts the selection. To get the position where the user ends the selection, use the active property.

var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
subDocument.insertText(position, 'text');
See Also

activeSubDocument Property

Returns the active sub-document.

Declaration

readonly activeSubDocument: SubDocumentBase

Property Value

Type Description
SubDocumentBase

The active sub-document.

Remarks

var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
subDocument.insertText(position, 'text');
See Also

anchor Property

Gets a position where a user starts the last selection.

Declaration

readonly anchor: number

Property Value

Type Description
number

The position of the selection anchor.

Remarks

Users can make a selection from left to right or from right to left. Use the anchor property to get the position where a user starts the selection. To get the position where the user ends the selection, use the active property.

end Property

Gets the end position of the last selected interval.

Declaration

readonly end: number

Property Value

Type Description
number

The end position.

intervals Property

Gets an array of document intervals in the selection.

Declaration

readonly intervals: Interval[]

Property Value

Type Description
Interval[]

An array of Interval objects.

See Also

showCursorAtEndOfLine Property

Specifies where to display the cursor when its position is on the border of two lines: at the end of the previous line or at the beginning of the new line.

Declaration

showCursorAtEndOfLine: boolean

Property Value

Type Description
boolean

true to display the cursor at the end of the previous line; false to display the cursor at the beginning of the new line.

start Property

Gets the start position of the last selected interval.

Declaration

readonly start: number

Property Value

Type Description
number

The start position.

Methods

goToSubDocumentEnd Method

Moves the cursor to the end of the sub-document and allows you to extend the selection.

Declaration

goToSubDocumentEnd(
    extendSelection?: boolean
): void

Parameters

Name Type Description
extendSelection boolean

true, to extend the selection; otherwise, false.

Remarks

richEdit.selection.goToSubDocumentEnd();

selectAll Method

Selects the current sub-document's entire content.

Declaration

selectAll(): void

Remarks

richEdit.selection.selectAll();
See Also

setSelection(position) Method

Selects the specified interval(s).

Declaration

setSelection(
    position: number | IInterval | IInterval[]
): void

Parameters

Name Type Description
position number | IInterval | IInterval[]

The interval(s) or position to select.

Remarks

var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
var templateText = '[Type your text here]';

richEdit.beginUpdate();
richEdit.history.beginTransaction();

position = subDocument.insertParagraph(position).interval.end;
position = subDocument.insertParagraph(position).interval.end;
position = subDocument.insertText(position, 'Dear Mr Stanley,').end;
position = subDocument.insertParagraph(position).interval.end;
var tmpTextInterval = subDocument.insertText(position, templateText);
position = tmpTextInterval.end;
position = subDocument.insertParagraph(position).interval.end;

richEdit.endUpdate();
richEdit.history.endTransaction();

richEdit.selection.setSelection(tmpTextInterval);
richEdit.focus();
See Also