Interface IContentSelection
The currently selected content in the edit control.
The selection is represented by two positions: From and Upto, where the from position is the start of the selection and the upto position is the active end of the selection, i.e. the end that typically moves when the user presses Shift + arrow keys, or selects text using the mouse.
When no content is selected the from and upto positions are the same. This can be tested through the IsEmpty property of the selection.
The selection can be made empty by explicitly calling CollapseToFrom() and CollapseToUpto().
The from position does not need to be before the upto position. This can happen e.g. if the user selects text starting from the right and moving left in the document. In such cases the selection is said to be reversed. This can be tested through the IsReversed property of the selection.
The from and upto positions of the selection can be swapped by calling the Reverse() method. Calling the Normalize() method ensures that the from position in the selection is not after the upto position, by testing if the selection is reversed and in that case reversing it.
The selection can be explicitly moved through the methods Move(Move, bool) and MoveTo(Position, bool).
The selection is never null
but may not always be valid. Use IsValid to test whether
the selection is in a safe state to use.
Namespace: SdlSdl.DesktopEditorEditorApi
Assembly: Sdl.DesktopEditor.EditorApi.dll
Syntax
public interface IContentSelection
Properties
Control
The edit control the selection belongs to.
Declaration
IEditControl Control { get; }
Property Value
Type | Description |
---|---|
IEditControl |
FileAtActiveEnd
Some editing operations should not work if the selection spans file boundaries. This method can be used for checking these condition.
Declaration
IFileContainerNode FileAtActiveEnd { get; }
Property Value
Type | Description |
---|---|
IFileContainerNode | The file container for the active end of the selection. |
FileAtNonactiveEnd
Some editing operations should not work if the selection spans file boundaries. This method can be used for checking these condition.
Declaration
IFileContainerNode FileAtNonactiveEnd { get; }
Property Value
Type | Description |
---|---|
IFileContainerNode | The file container for the non-active end of the selection. |
From
The start of the currently selected content in the edit control.
Declaration
Position From { get; set; }
Property Value
Type | Description |
---|---|
Position |
Remarks
This is the non-active end of the selection, i.e. the end that does not move when selecting text using arrow keys or the mouse (or the Move(Move, bool) or MoveTo(Position, bool) methods).
The From position may appear before the Upto position if the selection is reversed.
Assigning to this property moves the selection. If the selection is not visible it is also scrolled into view.
FromRow
The row at the From position of the current selection. Can be null
if there is
no row at that position (either because from is invalid or the layout has not be fully generated yet).
Declaration
IRowInfo FromRow { get; }
Property Value
Type | Description |
---|---|
IRowInfo |
Remarks
This property can also be used to gain access to the ISegmentContainerNode and the IParagraphUnitContainerNode at the from end of selection.
IsEmpty
Declaration
bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
bool |
See Also
IsReversed
Declaration
bool IsReversed { get; }
Property Value
Type | Description |
---|---|
bool |
See Also
IsValid
Tests whether the current selection is valid. The selection is valid when both from and upto positions are valid, otherwise it is not valid. This is useful for testing whether the selection has been initialized properly yet, or is visible on the screen.
Declaration
bool IsValid { get; }
Property Value
Type | Description |
---|---|
bool |
Upto
The active end of the currently selected content in the edit control.
Declaration
Position Upto { get; set; }
Property Value
Type | Description |
---|---|
Position |
Remarks
This is the part of the selection that moves when selecting text using arrow keys or the mouse (or the Move(Move, bool) or MoveTo(Position, bool) methods).
The Upto position may appear after the From position if the selection is reversed.
Assigning to this property moves the selection. If the selection is not visible it is also scrolled into view.
UptoRow
The row at the Upto position of the current selection. Can be null
if there is
no row at that position (either because upto is invalid or the layout has not be fully generated yet).
Declaration
IRowInfo UptoRow { get; }
Property Value
Type | Description |
---|---|
IRowInfo |
Remarks
This property can also be used to gain access to the ISegmentContainerNode and the IParagraphUnitContainerNode at the upto end of selection.
Methods
CollapseToFrom()
Declaration
void CollapseToFrom()
See Also
CollapseToUpto()
Declaration
void CollapseToUpto()
See Also
Contains(Position)
Determine if a position is inside the selection.
Declaration
bool Contains(Position position)
Parameters
Type | Name | Description |
---|---|---|
Position | position | The position to test. |
Returns
Type | Description |
---|---|
bool |
|
Remarks
The position is considered to be "inside" if it is at the same location as the first position in the selection (i.e. the From position if the range is normalized, or the Upto position if not). It is considered "outside" if it is at (i.e. same as) the last part of the selection. If the selection is empty the position is not considered to be "inside".
Move(Move, bool)
Move the selection relative to its current location.
Declaration
bool Move(Move direction, bool extendSelection)
Parameters
Type | Name | Description |
---|---|---|
Move | direction | Indicates how the selection should be moved. |
bool | extendSelection | If |
Returns
Type | Description |
---|---|
bool |
|
Remarks
If the selection is not visible it is automatically scrolled into view.
MoveTo(ContentRange)
Move the selection so that it spans the specified range.
Declaration
bool MoveTo(ContentRange range)
Parameters
Type | Name | Description |
---|---|---|
ContentRange | range | The range that the selection should span. |
Returns
Type | Description |
---|---|
bool |
|
Remarks
If the selection is not visible it is automatically scrolled into view.
MoveTo(Position, bool)
Move the selection to a specific location.
Declaration
bool MoveTo(Position destination, bool extendSelection)
Parameters
Type | Name | Description |
---|---|---|
Position | destination | The location to which the selection should be moved. |
bool | extendSelection | If |
Returns
Type | Description |
---|---|
bool |
|
Remarks
If the selection is not visible it is automatically scrolled into view.
Normalize()
Swaps the From and Upto positions if the selection is reversed, to ensure that From always appears before (or in the same place as) Upto.
Declaration
void Normalize()
Remarks
This operation has no effect if the selection is empty or if it is not reversed.
See Also
Reverse()
Declaration
void Reverse()
Remarks
This operation has no effect if the selection is empty.
See Also
ScrollIntoView()
Scroll the content at the current selection into view.
Declaration
void ScrollIntoView()
Remarks
Note that there is seldom a need to call this method as the selection is automatically scrolled into view when it is moved. However if you resize the window (for example) the selection may end up outside of the view as a result - calling this method will bring it back into view.
If the entire selection cannot be scrolled into view the Upto end of the selection should at least be scrolled in, with as much of the rest of the selection visible as possible.