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
get 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');
activeSubDocument Property
Returns the active sub-document.
Declaration
get 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');
anchor Property
Gets a position where a user starts the last selection.
Declaration
get 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
get end(): number
Property Value
Type | Description |
---|---|
number | The end position. |
intervals Property
Gets an array of document intervals in the selection.
Declaration
get intervals(): Interval[]
Property Value
Type | Description |
---|---|
Interval[] | An array of Interval objects. |
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
get showCursorAtEndOfLine(): boolean
set showCursorAtEndOfLine(value: boolean)
Property Value
Type | Description |
---|---|
boolean |
|
start Property
Gets the start position of the last selected interval.
Declaration
get start(): number
Property Value
Type | Description |
---|---|
number | The start position. |
Methods
goToDocumentEnd Method
Moves the cursor to the end of the active sub-document and allows you to extend the selection.
Declaration
goToDocumentEnd(
extendSelection?: boolean
): void
Parameters
Name | Type | Description |
---|---|---|
extendSelection | boolean | true to extend the selection; otherwise, false. |
Remarks
// Inserts text at the end of the active sub-document
richEdit.selection.goToDocumentEnd(false);
var position = richEdit.selection.active;
richEdit.selection.activeSubDocument.insertText(position, 'text');
goToDocumentStart Method
Moves the cursor to the start of the active sub-document and allows you to extend the selection.
Declaration
goToDocumentStart(
extendSelection?: boolean
): void
Parameters
Name | Type | Description |
---|---|---|
extendSelection | boolean | true to extend the selection; otherwise, false. |
Remarks
// Inserts text at the start of the active sub-document
richEdit.selection.goToDocumentStart(false);
var position = richEdit.selection.active;
richEdit.selection.activeSubDocument.insertText(position, 'text');
goToLineEnd Method
Moves the cursor to the end of the line and allows you to extend the selection.
Declaration
goToLineEnd(
extendSelection?: boolean
): void
Parameters
Name | Type | Description |
---|---|---|
extendSelection | boolean | true to extend the selection; otherwise, false. |
Remarks
richEdit.selection.goToLineEnd(true);
goToLineStart Method
Moves the cursor to the start of the line and allows you to extend the selection.
Declaration
goToLineStart(
extendSelection?: boolean
): void
Parameters
Name | Type | Description |
---|---|---|
extendSelection | boolean | true to extend the selection; otherwise, false. |
Remarks
richEdit.selection.goToLineStart(true);
goToNextCharacter Method
Moves the cursor to the next character and allows you to extend the selection.
Declaration
goToNextCharacter(
extendSelection?: boolean
): void
Parameters
Name | Type | Description |
---|---|---|
extendSelection | boolean | true to extend the selection; otherwise, false. |
Remarks
richEdit.selection.goToNextCharacter(true);
goToNextLine Method
Moves the cursor to the next line and allows you to extend the selection.
Declaration
goToNextLine(
extendSelection?: boolean
): void
Parameters
Name | Type | Description |
---|---|---|
extendSelection | boolean | true to extend the selection; otherwise, false. |
Remarks
Moves the cursor one line down. If the current line is the last one, moves the cursor to the end of the current line.
Use the goToLineStart/goToLineEnd method to move the cursor to the start/end of the line.
// Moves the cursor to the start of the next line
richEdit.selection.goToNextLine(false);
richEdit.selection.goToLineStart(false);
goToNextPage Method
Moves the cursor to the next page and allows you to extend the selection.
Declaration
goToNextPage(
extendSelection?: boolean
): void
Parameters
Name | Type | Description |
---|---|---|
extendSelection | boolean | true to extend the selection; otherwise, false. |
Remarks
Moves the cursor one page down. If the current page is the last one, moves the cursor to the end of the current page.
richEdit.selection.goToNextPage(true);
goToNextPageStart Method
Moves the cursor to the start of the next page and allows you to extend the selection.
Declaration
goToNextPageStart(
extendSelection?: boolean
): void
Parameters
Name | Type | Description |
---|---|---|
extendSelection | boolean | true to extend the selection; otherwise, false. |
Remarks
richEdit.selection.goToNextPageStart(true);
goToNextWord Method
Moves the cursor to the next word and allows you to extend the selection.
Declaration
goToNextWord(
extendSelection?: boolean
): void
Parameters
Name | Type | Description |
---|---|---|
extendSelection | boolean | true to extend the selection; otherwise, false. |
Remarks
This method treats most punctuation marks as separate words.
richEdit.selection.goToNextWord(true);
goToParagraphEnd Method
Moves the cursor to the end of the paragraph and allows you to extend the selection.
Declaration
goToParagraphEnd(
extendSelection?: boolean
): void
Parameters
Name | Type | Description |
---|---|---|
extendSelection | boolean | true to extend the selection; otherwise, false. |
Remarks
Moves the cursor to the end of the current paragraph. If the cursor is at the end of a paragraph, moves the cursor to the end of the next paragraph.
richEdit.selection.goToParagraphEnd(true);
goToParagraphStart Method
Moves the cursor to the start of the paragraph and allows you to extend the selection.
Declaration
goToParagraphStart(
extendSelection?: boolean
): void
Parameters
Name | Type | Description |
---|---|---|
extendSelection | boolean | true to extend the selection; otherwise, false. |
Remarks
Moves the cursor to the start of the current paragraph. If the cursor is at the start of a paragraph, moves the cursor to the start of the previous paragraph.
richEdit.selection.goToParagraphStart(true);
goToPreviousCharacter Method
Moves the cursor to the previous character and allows you to extend the selection.
Declaration
goToPreviousCharacter(
extendSelection?: boolean
): void
Parameters
Name | Type | Description |
---|---|---|
extendSelection | boolean | true to extend the selection; otherwise, false. |
Remarks
richEdit.selection.goToPreviousCharacter(true);
goToPreviousLine Method
Moves the cursor to the previous line and allows you to extend the selection.
Declaration
goToPreviousLine(
extendSelection?: boolean
): void
Parameters
Name | Type | Description |
---|---|---|
extendSelection | boolean | true to extend the selection; otherwise, false. |
Remarks
Moves the cursor one line up. If the current line is the first one, moves the cursor to the start of the current line.
Use the goToLineStart/goToLineEnd method to move the cursor to the start/end of the line.
// Moves the cursor to the start of the previous line
richEdit.selection.goToPreviousLine(false);
richEdit.selection.goToLineStart(false);
goToPreviousPage Method
Moves the cursor to the previous page and allows you to extend the selection.
Declaration
goToPreviousPage(
extendSelection?: boolean
): void
Parameters
Name | Type | Description |
---|---|---|
extendSelection | boolean | true to extend the selection; otherwise, false. |
Remarks
Moves the cursor one page up. If the current page is the first one, moves the cursor to the start of the current page.
richEdit.selection.goToPreviousPage(true);
goToPreviousPageStart Method
Moves the cursor to the start of the previous page and allows you to extend the selection.
Declaration
goToPreviousPageStart(
extendSelection?: boolean
): void
Parameters
Name | Type | Description |
---|---|---|
extendSelection | boolean | true to extend the selection; otherwise, false. |
Remarks
richEdit.selection.goToPreviousPageStart(true);
goToPreviousWord Method
Moves the cursor to the previous word and allows you to extend the selection.
Declaration
goToPreviousWord(
extendSelection?: boolean
): void
Parameters
Name | Type | Description |
---|---|---|
extendSelection | boolean | true to extend the selection; otherwise, false. |
Remarks
This method treats most punctuation marks as separate words.
richEdit.selection.goToPreviousWord(true);
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();
selectLine Method
Selects the line in which the cursor is located and allows you to extend the selection.
Declaration
selectLine(
extendSelection?: boolean
): void
Parameters
Name | Type | Description |
---|---|---|
extendSelection | boolean | true to extend the selection; otherwise, false. |
Remarks
When the end of the current line is already selected, the method selects the next line.
// Selects five lines
for(let i=0; i<5; i++)
richEdit.selection.selectLine(true);
selectParagraph Method
Selects the paragraph in which the cursor is located.
Declaration
selectParagraph(): void
Remarks
richEdit.selection.selectParagraph();
selectTable Method
Selects the entire table in which the cursor is located.
Declaration
selectTable(): void
Remarks
richEdit.selection.selectTable();
selectTableCell Method
Selects the table cell in which the cursor is located.
Declaration
selectTableCell(): void
Remarks
richEdit.selection.selectTableCell();
selectTableRow Method
Selects the table row in which the cursor is located.
Declaration
selectTableRow(): void
Remarks
richEdit.selection.selectTableRow();
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();