In This Article

IEditorViewSelection Interface

Provides the base requirements for an object that tracks the selection of an IEditorView.

public interface IEditorViewSelection

Properties

CaretCharacterColumn

Gets the character column of the primary selection's caret.

int CaretCharacterColumn { get; }

Property Value

System.Int32:

The character column of the primary selection's caret.

Remarks

This property is the same as calling the GetCharacterColumn(Int32, Boolean) method using the value of the EndPosition property.

CaretDisplayCharacterColumn

Gets the character column of the primary selection's caret, adding one to the value for display purposes.

int CaretDisplayCharacterColumn { get; }

Property Value

System.Int32:

The CaretCharacterColumn property value, offset by one.

CaretOffset

Gets or sets the offset of the primary selection's caret.

int CaretOffset { get; set; }

Property Value

System.Int32:

The offset of the primary selection's caret.

Remarks

This property is the same as getting the EndOffset property and setting the StartOffset property.

CaretPosition

Gets or sets the TextPosition of the primary selection's caret.

TextPosition CaretPosition { get; set; }

Property Value

TextPosition:

The TextPosition of the primary selection's caret.

Remarks

This property is the same as getting the EndPosition property and setting the StartPosition property.

EndOffset

Gets or sets the end offset of the primary selection range.

int EndOffset { get; set; }

Property Value

System.Int32:

The end offset of the primary selection range.

Remarks

The end offset may occur before the start offset if the selection range is not normalized. The IsNormalized property indicates if the selection range is normalized. To get the normalized first offset in the selection range, use the FirstOffset property. To get the normalized last offset in the selection range, use the LastOffset property.

EndPosition

Gets or sets the TextPosition that represents the end of the primary selection range.

TextPosition EndPosition { get; set; }

Property Value

TextPosition:

The TextPosition that represents the end of the primary selection range.

Remarks

This property's value comes from the end TextPosition of the PositionRange property. The EndPosition may occur before the StartPosition if the selection range is not normalized. The IsNormalized property indicates if the selection range is normalized. To get the normalized first TextPosition in the selection range, use the FirstPosition property. To get the normalized last TextPosition in the selection range, use the LastPosition property.

EndSnapshotOffset

Gets the TextSnapshotOffset that specifies the end offset of the primary selection range.

TextSnapshotOffset EndSnapshotOffset { get; }

Property Value

TextSnapshotOffset:

The TextSnapshotOffset that specifies the end offset of the primary selection range.

Remarks

The start offset may occur after the end offset if the selection range is not normalized. The IsNormalized property indicates if the selection range is normalized.

FirstOffset

Gets the first offset in the primary selection range.

int FirstOffset { get; }

Property Value

System.Int32:

The first offset in the primary selection range.

Remarks

This property returns either the StartOffset or EndOffset property, whichever comes first.

FirstPosition

Gets the first TextPosition in the primary selection range.

TextPosition FirstPosition { get; }

Property Value

TextPosition:

The first TextPosition in the primary selection range.

Remarks

This property returns either the StartPosition or EndPosition property, whichever comes first.

IsNormalized

Gets whether the primary selection range is normalized (StartPosition occurs at or before the EndPosition).

bool IsNormalized { get; }

Property Value

System.Boolean:

true if the primary selection range is normalized; otherwise, false.

IsReadOnly

Gets whether any character in the selection ranges are flagged as read-only.

bool IsReadOnly { get; }

Property Value

System.Boolean:

true if any character in the selection ranges are flagged as read-only; otherwise, false.

IsZeroLength

Gets whether the primary selection range has a zero length.

bool IsZeroLength { get; }

Property Value

System.Boolean:

true if the primary selection range has a zero length; otherwise, false.

LastOffset

Gets the last offset in the primary selection range.

int LastOffset { get; }

Property Value

System.Int32:

The last offset in the primary selection range.

Remarks

This property returns either the StartOffset or EndOffset property, whichever comes last.

LastPosition

Gets the last TextPosition in the primary selection range.

TextPosition LastPosition { get; }

Property Value

TextPosition:

The last TextPosition in the primary selection range.

Remarks

This property returns either the StartPosition or EndPosition property, whichever comes last.

Length

Gets the absolute offset length of the primary selection range.

int Length { get; }

Property Value

System.Int32:

The absolute offset length of the primary selection range.

Remarks

This value is always positive.

Mode

Gets a SelectionModes that indicates the selection mode currently in use.

SelectionModes Mode { get; }

Property Value

SelectionModes:

A SelectionModes that indicates the selection mode currently in use.

PositionRange

Gets or sets the TextPositionRange that describes the start and end TextPosition of the primary selection.

TextPositionRange PositionRange { get; set; }

Property Value

TextPositionRange:

The TextPositionRange that describes the start and end TextPosition of the primary selection.

Ranges

Gets the collection of selection ranges in the view.

ITextPositionRangeCollection Ranges { get; }

Property Value

ITextPositionRangeCollection:

The collection of selection ranges in the view.

Remarks

This collection ordinarily contains a single range, but can have more than one range when there are multiple selections. Each selection range has its own caret at the selection range's end position.

SnapshotRange

Gets the TextSnapshotRange that specifies the offset range of the primary selection.

TextSnapshotRange SnapshotRange { get; }

Property Value

TextSnapshotRange:

The TextSnapshotRange that specifies the offset range of the primary selection.

StartOffset

Gets or sets the start offset of the primary selection range.

int StartOffset { get; set; }

Property Value

System.Int32:

The start offset of the primary selection range.

Remarks

The start offset may occur after the end offset if the selection range is not normalized. The IsNormalized property indicates if the selection range is normalized. To get the normalized first offset in the selection range, use the FirstOffset property. To get the normalized last offset in the selection range, use the LastOffset property.

StartPosition

Gets or sets the TextPosition that represents the start of the primary selection range.

TextPosition StartPosition { get; set; }

Property Value

TextPosition:

The TextPosition that represents the start of the primary selection range.

Remarks

This property's value comes from the start TextPosition of the PositionRange property. The StartPosition may occur after the EndPosition if the selection range is not normalized. The IsNormalized property indicates if the selection range is normalized. To get the normalized first TextPosition in the selection range, use the FirstPosition property. To get the normalized last TextPosition in the selection range, use the LastPosition property.

StartSnapshotOffset

Gets the TextSnapshotOffset that specifies the start offset of the primary selection range.

TextSnapshotOffset StartSnapshotOffset { get; }

Property Value

TextSnapshotOffset:

The TextSnapshotOffset that specifies the start offset of the primary selection range.

Remarks

The start offset may occur after the end offset if the selection range is not normalized. The IsNormalized property indicates if the selection range is normalized.

TextRange

Gets or sets the TextRange that specifies the offset range of the primary selection.

TextRange TextRange { get; set; }

Property Value

TextRange:

The TextRange that specifies the offset range of the primary selection.

Methods

AddNextOccurrence()

Adds the next occurrence of the currently-selected text to the selection, or selects the current word if there is no selection.

void AddNextOccurrence()

AddRange(TextPositionRange)

Adds a new selection range to the Ranges collection.

void AddRange(TextPositionRange positionRange)
Parameter Type Description
positionRange TextPositionRange

The TextPositionRange containing the range of characters to select.

Remarks

This method results in multiple selection ranges and related carets.

CaptureState()

Captures the current IEditorViewSelectionState and allows it to be restored later for a different snapshot.

IEditorViewSelectionState CaptureState()

Returns

IEditorViewSelectionState:

An IEditorViewSelectionState that represents the current selection state.

Remarks

When capturing the selection state, the future restoration should be performed immediately after any programmatic text changes that are made following the capture.

CaptureState(TextRangeTrackingModes)

Captures the current IEditorViewSelectionState and allows it to be restored later for a different snapshot.

IEditorViewSelectionState CaptureState(TextRangeTrackingModes trackingModes)
Parameter Type Description
trackingModes TextRangeTrackingModes

The TextRangeTrackingModes to use for translating between snapshots.

Returns

IEditorViewSelectionState:

An IEditorViewSelectionState that represents the current selection state.

Remarks

When capturing the selection state, the future restoration should be performed immediately after any programmatic text changes that are made following the capture.

CodeBlockContract()

Contracts the selection to encompass a range previously expanded by a call to CodeBlockExpand().

bool CodeBlockContract()

Returns

System.Boolean:

true of selection was contracted; otherwise, false.

Remarks

This method iterates backward through the selection history produced by calls to CodeBlockExpand(). The code block selection history resets after any other selection or text changes.

CodeBlockExpand()

Expands the selection to encompass a larger range based on surrounding code blocks.

bool CodeBlockExpand()

Returns

System.Boolean:

true of selection was expanded; otherwise, false.

Remarks

Syntax languages can implement an ICodeBlockFinder service to support this feature.

Collapse()

Collapses the selection ranges.

void Collapse()

CollapseLeft()

Collapses the selection ranges to the left.

void CollapseLeft()

CollapseRight()

Collapse the selection ranges to the right.

void CollapseRight()

Contains(TextPosition)

Returns whether a selection range contains the specified TextPosition.

bool Contains(TextPosition position)
Parameter Type Description
position TextPosition

The TextPosition to check.

Returns

System.Boolean:

true if a selection range contains the specified TextPosition; otherwise false.

Contains(Int32)

Returns whether a selection range contains the specified offset.

bool Contains(int offset)
Parameter Type Description
offset System.Int32

The offset to check.

Returns

System.Boolean:

true if a selection range contains the specified offset; otherwise false.

CreateBatch(EditorViewSelectionBatchOptions)

Creates an System.IDisposable object such that while the object is not disposed, selection events will be suspended while a batch of selection changes are made.

IDisposable CreateBatch(EditorViewSelectionBatchOptions options)
Parameter Type Description
options EditorViewSelectionBatchOptions

An EditorViewSelectionBatchOptions that indicates batch options.

Returns

System.IDisposable:

An System.IDisposable object. Once disposed, the batch is ended.

GetPreferredCaretHorizontalLocations()

Returns the collection of preferred caret horizontal locations.

IList<double> GetPreferredCaretHorizontalLocations()

Returns

System.Collections.Generic.IList<System.Double>:

The collection of preferred caret horizontal locations.

Remarks

The returned collection will have the same number of items as the Ranges collection.

GetTextRanges()

Returns the collection of TextRange objects that specify the ranges of text that is selected.

IList<TextRange> GetTextRanges()

Returns

System.Collections.Generic.IList<TextRange>:

The collection of TextRange objects that specify the ranges of text that is selected.

Remarks

Normally a single TextRange is returned. However in the case of a block selection or multiple selection ranges, more than one TextRange can be returned.

GetTextRanges(Int32)

Returns the collection of TextRange objects that specify the ranges of text that is selected.

IList<TextRange> GetTextRanges(int minimumLines)
Parameter Type Description
minimumLines System.Int32

The minimum number of lines to return when the selection is a block selection.

Returns

System.Collections.Generic.IList<TextRange>:

The collection of TextRange objects that specify the ranges of text that is selected.

Remarks

Normally a single TextRange is returned. However in the case of a block selection or multiple selection ranges, more than one TextRange can be returned.

MoveDown()

Moves the carets down a line.

void MoveDown()

MoveLeft()

Moves the carets left a character.

void MoveLeft()

MovePageDown()

Moves the carets down a page.

void MovePageDown()

MovePageUp()

Moves the carets up a page.

void MovePageUp()

MoveRight()

Moves the carets right a character.

void MoveRight()

MoveToDocumentEnd()

Moves the caret to the end of the document.

void MoveToDocumentEnd()

MoveToDocumentStart()

Moves the caret to the start of the document.

void MoveToDocumentStart()

MoveToLineEnd()

Moves the carets to the end of their current lines.

void MoveToLineEnd()

MoveToLineStart()

Moves the carets to the start of their current lines.

void MoveToLineStart()

MoveToLineStartAfterIndentation()

Moves the carets to the first non-whitespace character on their current lines.

void MoveToLineStartAfterIndentation()

MoveToMatchingBracket()

Moves the caret to the matching bracket.

void MoveToMatchingBracket()

MoveToNextLineStartAfterIndentation()

Moves the caret to the first non-whitespace character on the next view line.

void MoveToNextLineStartAfterIndentation()

MoveToNextWord()

Moves the carets to the next word.

void MoveToNextWord()

MoveToPreviousLineStartAfterIndentation()

Moves the caret to the first non-whitespace character on the previous view line.

void MoveToPreviousLineStartAfterIndentation()

MoveToPreviousWord()

Moves the carets to the previous word.

void MoveToPreviousWord()

MoveToVisibleBottom()

Moves the caret to the bottom of the view.

void MoveToVisibleBottom()

MoveToVisibleTop()

Moves the caret to the top of the view.

void MoveToVisibleTop()

MoveUp()

Moves the carets up a line.

void MoveUp()

SelectAll()

Selects all of the text.

void SelectAll()

SelectBlockDown()

Block selects down a line.

void SelectBlockDown()

SelectBlockLeft()

Block selects left a character.

void SelectBlockLeft()

SelectBlockRight()

Block selects right a character.

void SelectBlockRight()

SelectBlockToNextWord()

Block selects to the next word.

void SelectBlockToNextWord()

SelectBlockToPreviousWord()

Block selects to the previous word.

void SelectBlockToPreviousWord()

SelectBlockUp()

Block selects up a line.

void SelectBlockUp()

SelectDown()

Selects down a line.

void SelectDown()

SelectLeft()

Selects left a character.

void SelectLeft()

SelectPageDown()

Selects down a page.

void SelectPageDown()

SelectPageUp()

Selects up a page.

void SelectPageUp()

SelectRange(TextPosition, TextPosition)

Selects a single range of text using a pair of TextPosition objects.

void SelectRange(TextPosition startPosition, TextPosition endPosition)
Parameter Type Description
startPosition TextPosition

The TextPosition at which to start the selection.

endPosition TextPosition

The TextPosition at which to end the selection.

SelectRange(TextPosition, TextPosition, SelectionModes)

Selects a range of text using a pair of TextPosition objects.

void SelectRange(TextPosition startPosition, TextPosition endPosition, SelectionModes mode)
Parameter Type Description
startPosition TextPosition

The TextPosition at which to start the selection.

endPosition TextPosition

The TextPosition at which to end the selection.

mode SelectionModes

The SelectionModes to use. This value must be either SelectionModes.ContinuousStream or SelectionModes.Block.

SelectRange(TextPositionRange)

Selects a single range of text using a TextPositionRange.

void SelectRange(TextPositionRange positionRange)
Parameter Type Description
positionRange TextPositionRange

The TextPositionRange containing the range of characters to select.

SelectRange(TextPositionRange, SelectionModes)

Selects a single range of text using a TextPositionRange.

void SelectRange(TextPositionRange positionRange, SelectionModes mode)
Parameter Type Description
positionRange TextPositionRange

The TextPositionRange containing the range of characters to select.

mode SelectionModes

The SelectionModes to use. This value must be either SelectionModes.ContinuousStream or SelectionModes.Block.

SelectRange(TextRange)

Selects a single range of text using a TextRange.

void SelectRange(TextRange textRange)
Parameter Type Description
textRange TextRange

The TextRange containing the range of characters to select.

SelectRange(TextRange, SelectionModes)

Selects a single range of text using a TextRange.

void SelectRange(TextRange textRange, SelectionModes mode)
Parameter Type Description
textRange TextRange

The TextRange containing the range of characters to select.

mode SelectionModes

The SelectionModes to use. This value must be either SelectionModes.ContinuousStream or SelectionModes.Block.

SelectRange(Int32, Int32)

Selects a single range of text using an offset and length.

void SelectRange(int offset, int length)
Parameter Type Description
offset System.Int32

The offset at which to start the selection.

length System.Int32

The number of characters to select.

SelectRange(Int32, Int32, SelectionModes)

Selects a single range of text using an offset and length.

void SelectRange(int offset, int length, SelectionModes mode)
Parameter Type Description
offset System.Int32

The offset at which to start the selection.

length System.Int32

The number of characters to select.

mode SelectionModes

The SelectionModes to use. This value must be either SelectionModes.ContinuousStream or SelectionModes.Block.

SelectRanges(IEnumerable<TextPositionRange>)

Selects multiple Ranges of text using a collection of TextPositionRange objects.

void SelectRanges(IEnumerable<TextPositionRange> positionRanges)
Parameter Type Description
positionRanges System.Collections.Generic.IEnumerable<TextPositionRange>

The collection of TextPositionRange objects containing the ranges of characters to select.

Remarks

This method will switch the Mode to ContinuousStream.

SelectRanges(IEnumerable<TextPositionRange>, Nullable<Int32>)

Selects multiple Ranges of text using a collection of TextPositionRange objects.

void SelectRanges(IEnumerable<TextPositionRange> positionRanges, int? primaryIndex)
Parameter Type Description
positionRanges System.Collections.Generic.IEnumerable<TextPositionRange>

The collection of TextPositionRange objects containing the ranges of characters to select.

primaryIndex System.Nullable<System.Int32>

The positionRanges item index to make the new primary selection range.

Remarks

This method will switch the Mode to ContinuousStream.

SelectRight()

Selects right a character.

void SelectRight()

SelectToDocumentEnd()

Selects to the end of the document.

void SelectToDocumentEnd()

SelectToDocumentStart()

Selects to the start of the document.

void SelectToDocumentStart()

SelectToLineEnd()

Selects to the end of the current lines.

void SelectToLineEnd()

SelectToLineStart()

Selects to the start of the current lines.

void SelectToLineStart()

SelectToLineStartAfterIndentation()

Selects to the first non-whitespace character on the current lines.

void SelectToLineStartAfterIndentation()

SelectToMatchingBracket()

Selects to the matching bracket.

void SelectToMatchingBracket()

SelectToNextWord()

Selects to the next word.

void SelectToNextWord()

SelectToPreviousWord()

Selects to the previous word.

void SelectToPreviousWord()

SelectToVisibleBottom()

Selects to the bottom of the view.

void SelectToVisibleBottom()

SelectToVisibleTop()

Selects to the top of the view.

void SelectToVisibleTop()

SelectUp()

Selects up a line.

void SelectUp()

SelectWord()

Selects the current word.

void SelectWord()

ToggleRange(TextPositionRange)

Toggles a selection range in the Ranges collection.

bool ToggleRange(TextPositionRange positionRange)
Parameter Type Description
positionRange TextPositionRange

The TextPositionRange containing the range of characters to select.

Returns

System.Boolean:

true if a selection range was added/merged; otherwise, false.

Remarks

This method can result in multiple selection ranges and related carets. If the specified selection range exactly matches an existing selection range, the existing selection range will be removed. Otherwise, any existing selection ranges that intersect will be removed, and the specified selection range will be added.