Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

RichEditSelection Class

In This Article

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

#Declaration

TypeScript
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

TypeScript
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');
See Also

#activeSubDocument Property

Returns the active sub-document.

#Declaration

TypeScript
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');
See Also

#anchor Property

Gets a position where a user starts the last selection.

#Declaration

TypeScript
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

TypeScript
get end(): number

#Property Value

Type Description
number

The end position.

#intervals Property

Gets an array of document intervals in the selection.

#Declaration

TypeScript
get 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

TypeScript
get showCursorAtEndOfLine(): boolean
set showCursorAtEndOfLine(value: 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

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
selectAll(): void

#Remarks

richEdit.selection.selectAll();
See Also

#selectLine Method

Selects the line in which the cursor is located and allows you to extend the selection.

#Declaration

TypeScript
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

TypeScript
selectParagraph(): void

#Remarks

richEdit.selection.selectParagraph();

#selectTable Method

Selects the entire table in which the cursor is located.

#Declaration

TypeScript
selectTable(): void

#Remarks

richEdit.selection.selectTable();

#selectTableCell Method

Selects the table cell in which the cursor is located.

#Declaration

TypeScript
selectTableCell(): void

#Remarks

richEdit.selection.selectTableCell();

#selectTableRow Method

Selects the table row in which the cursor is located.

#Declaration

TypeScript
selectTableRow(): void

#Remarks

richEdit.selection.selectTableRow();

#setSelection(position) Method

Selects the specified interval(s).

#Declaration

TypeScript
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