Search Results for

    Show / Hide Table of Contents

    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, Boolean) and MoveTo(Position, Boolean).

    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: Sdl.DesktopEditor.EditorApi
    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, Boolean) or MoveTo(Position, Boolean) 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

    true if the selection is empty (when the From position is equivalent to the Upto position).

    Declaration
    bool IsEmpty { get; }
    Property Value
    Type Description
    System.Boolean
    See Also
    CollapseToFrom()
    CollapseToUpto()

    IsReversed

    true if the selection is reversed (the Upto position is before the From position).

    Declaration
    bool IsReversed { get; }
    Property Value
    Type Description
    System.Boolean
    See Also
    Reverse()
    Normalize()

    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
    System.Boolean

    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, Boolean) or MoveTo(Position, Boolean) 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()

    Makes the selection empty by moving Upto to the From position.

    Declaration
    void CollapseToFrom()
    See Also
    IsEmpty
    CollapseToUpto()

    CollapseToUpto()

    Makes the selection empty by moving From to the Upto position.

    Declaration
    void CollapseToUpto()
    See Also
    IsEmpty
    CollapseToFrom()

    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
    System.Boolean

    true if the position is considered to be inside the selection.

    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, Boolean)

    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.

    System.Boolean extendSelection

    If true only the active end (Upto) is moved. If false both From and Upto are moved.

    Returns
    Type Description
    System.Boolean

    true if the selection was moved as a result of the operation. (For example moving to the start of the line when the selection is already at the start of the line will not change the selection.)

    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
    System.Boolean

    true if the selection was moved as a result of this operation.

    Remarks

    If the selection is not visible it is automatically scrolled into view.

    MoveTo(Position, Boolean)

    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.

    System.Boolean extendSelection

    If true only the active end (Upto) is moved. If false both From and Upto are moved.

    Returns
    Type Description
    System.Boolean

    true if the selection was moved as a result of the operation.

    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
    IsReversed
    Reverse()

    Reverse()

    Swaps the From and Upto positions.

    Declaration
    void Reverse()
    Remarks

    This operation has no effect if the selection is empty.

    See Also
    IsReversed
    Normalize()

    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.

    Extension Methods

    WindowsControlUtils.ForWindowFromFrameworkElement(Object, Action<Window>)

    On this page

    • Properties
      • Control
      • FileAtActiveEnd
      • FileAtNonactiveEnd
      • From
      • FromRow
      • IsEmpty
      • IsReversed
      • IsValid
      • Upto
      • UptoRow
    • Methods
      • CollapseToFrom()
      • CollapseToUpto()
      • Contains(Position)
      • Move(Move, Boolean)
      • MoveTo(ContentRange)
      • MoveTo(Position, Boolean)
      • Normalize()
      • Reverse()
      • ScrollIntoView()
    • Extension Methods
    Back to top Generated by DocFX