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 position where a user ends the last selection.
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.
//Inserts a text at the cursor position
richEdit.selection.activeSubDocument.insertText(richEdit.selection.active,'sometext');
activeSubDocument Property
Returns the active sub-document.
Declaration
readonly activeSubDocument: SubDocumentBaseApi
Property Value
Type | Description |
---|---|
SubDocumentBaseApi | The active sub-document. |
Remarks
//Inserts a text at the cursor position
richEdit.selection.activeSubDocument.insertText(richEdit.selection.active,'sometext');
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. |
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(true);
selectAll Method
Selects the editor’s entire content.
Declaration
selectAll(): void
Remarks
richEdit.selection.selectAll();
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
function onDocumentLoaded(s, e) {
s.document.insertText(0, 'Dear Mr Stanley,');
s.document.insertParagraph(s.document.length);
var startPosition = s.document.length;
s.document.insertParagraph(startPosition);
s.document.insertText(startPosition, '[Type your text here]');
s.selection.setSelection(new DevExpress.RichEdit.Interval(startPosition, s.document.length - startPosition));
s.focus();
}
For a full example, see Ribbon Customization demo.