In This Article

TextRangeProvider Class

Exposes text snapshot ranges to UI Automation for a specified IEditorView.

public class TextRangeProvider
Inheritance:
object object

Constructors

TextRangeProvider(IEditorView, TextRange)

Initializes a new instance of the TextRangeProvider class.

public TextRangeProvider(IEditorView view, TextRange textRange)
Parameter Type Description
view IEditorView

The owner IEditorView.

textRange TextRange

The text range.

Methods

AddToSelection()

Adds to the collection of highlighted text in a text container that supports multiple, disjoint selections.

public virtual void AddToSelection()

Exceptions

Type Condition
InvalidOperationException

If text provider does not support multiple, disjoint selections (that is, ITextProvider.SupportedTextSelection must have a value of Multiple).

Clone()

Returns a new ITextRangeProvider identical to the original ITextRangeProvider and inheriting all properties of the original.

public virtual ITextRangeProvider Clone()

Returns

ITextRangeProvider:

The new text range. A null reference is never returned.

Compare(ITextRangeProvider)

Returns a value that indicates whether the span of a text range is the same as another text range.

public virtual bool Compare(ITextRangeProvider range)
Parameter Type Description
range ITextRangeProvider

A text range to compare

Returns

bool:

true if the span of both text ranges is identical; otherwise false.

Exceptions

Type Condition
ArgumentException

If the range being compared does not come from the same text provider.

CompareEndpoints(TextPatternRangeEndpoint, ITextRangeProvider, TextPatternRangeEndpoint)

Returns a value that specifies whether two text ranges have identical endpoints.

public virtual int CompareEndpoints(TextPatternRangeEndpoint endpoint, ITextRangeProvider targetRange, TextPatternRangeEndpoint targetEndpoint)
Parameter Type Description
endpoint TextPatternRangeEndpoint

The TextPatternRangeEndpoint.Start or TextPatternRangeEndpoint.End endpoint of the caller.

targetRange ITextRangeProvider

The target range for comparison.

targetEndpoint TextPatternRangeEndpoint

The TextPatternRangeEndpoint.Start or TextPatternRangeEndpoint.End endpoint of the target.

Returns

int:

Returns a negative value if the caller's endpoint occurs earlier in the text than the target endpoint. Returns zero if the caller's endpoint is at the same location as the target endpoint. Returns a positive value if the caller's endpoint occurs later in the text than the target endpoint.

Exceptions

Type Condition
ArgumentException

If targetRange is from a different text provider.

ExpandToEnclosingUnit(TextUnit)

Expands the text range to the specified text unit.

public virtual void ExpandToEnclosingUnit(TextUnit unit)
Parameter Type Description
unit TextUnit

The textual unit.

FindAttribute(int, object, bool)

Returns a text range subset that has the specified attribute value.

public virtual ITextRangeProvider FindAttribute(int attribute, object value, bool backward)
Parameter Type Description
attribute int

The attribute to search for.

value object

The attribute value to search for. This value must match the type specified for the attribute.

backward bool

true if the last occurring text range should be returned instead of the first; otherwise false.

Returns

ITextRangeProvider:

A text range having a matching attribute and attribute value; otherwise null.

FindText(string, bool, bool)

Returns a text range subset that contains the specified text.

public virtual ITextRangeProvider FindText(string text, bool backward, bool ignoreCase)
Parameter Type Description
text string

The text string to search for.

backward bool

true if the last occurring text range should be returned instead of the first; otherwise false.

ignoreCase bool

true if case should be ignored; otherwise false.

Returns

ITextRangeProvider:

A text range matching the specified text; otherwise null (Nothing in Microsoft Visual Basic .NET).

GetAttributeValue(int)

Retrieves the value of the specified attribute across the text range.

public virtual object GetAttributeValue(int attribute)
Parameter Type Description
attribute int

The text attribute.

Returns

object:

Retrieves an object representing the value of the specified attribute. For example, GetAttributeValue(TextPattern.FontNameAttribute) would return a string that represents the font name of the text range while GetAttributeValue(TextPattern.IsItalicAttribute) would return a value of type bool. Returns TextPattern.MixedAttributeValue if the value of the specified attribute varies over the text range. Returns AutomationElement.NotSupported if the specified attribute is not supported by the provider or the control.

Exceptions

Type Condition
ArgumentException

If the specified attribute is not valid.

GetBoundingRectangles()

Retrieves a collection of bounding rectangles for each fully or partially visible line of text in a text range.

public virtual double[] GetBoundingRectangles()

Returns

double[]:

An array of bounding rectangles for each full or partial line of text in a text range. An empty array for a degenerate range. An empty array for a text range that has screen coordinates placing it completely off-screen, scrolled out of view, or obscured by an overlapping window.

GetChildren()

Retrieves a collection of all embedded objects that fall within the text range.

public virtual IRawElementProviderSimple[] GetChildren()

Returns

IRawElementProviderSimple[]:

A collection of child objects that fall within the range. Children that overlap with the text range but are not entirely enclosed by it will also be included in the collection. Returns an empty collection if there are no child objects.

GetEnclosingElement()

Returns the innermost control that encloses the text range.

public virtual IRawElementProviderSimple GetEnclosingElement()

Returns

IRawElementProviderSimple:

The enclosing control, typically the text provider that supplies the text range. However, if the text provider supports child elements such as tables or hyperlinks, then the enclosing element could be a descendant of the text provider.

GetText(int)

Retrieves the plain text of the range.

public virtual string GetText(int maxLength)
Parameter Type Description
maxLength int

The maximum length of the string to return. Use -1 if no limit is required.

Returns

string:

The plain text of the text range, possibly truncated at the specified max length.

Move(TextUnit, int)

Moves the text range the specified number of text units.

public virtual int Move(TextUnit unit, int count)
Parameter Type Description
unit TextUnit

The text unit boundary.

count int

The number of text units to move. A positive value moves the text range forward, a negative value moves the text range backward, and 0 has no effect.

Returns

int:

The number of units actually moved. This can be less than the number requested if either of the new text range endpoints is greater than or less than the ITextProvider.DocumentRange endpoints.

MoveEndpointByRange(TextPatternRangeEndpoint, ITextRangeProvider, TextPatternRangeEndpoint)

Moves one endpoint of a text range to the specified endpoint of a second text range.

public virtual void MoveEndpointByRange(TextPatternRangeEndpoint endpoint, ITextRangeProvider targetRange, TextPatternRangeEndpoint targetEndpoint)
Parameter Type Description
endpoint TextPatternRangeEndpoint

The endpoint to move.

targetRange ITextRangeProvider

Another range from the same text provider.

targetEndpoint TextPatternRangeEndpoint

An endpoint on the other range.

MoveEndpointByUnit(TextPatternRangeEndpoint, TextUnit, int)

Moves one endpoint of the text range the specified number of text units within the document range.

public virtual int MoveEndpointByUnit(TextPatternRangeEndpoint endpoint, TextUnit unit, int count)
Parameter Type Description
endpoint TextPatternRangeEndpoint

The endpoint to move.

unit TextUnit

The textual unit for moving.

count int

The number of units to move. A positive value moves the endpoint forward. A negative value moves backward. A value of 0 has no effect.

Returns

int:

The number of units actually moved, which can be less than the number requested if moving the endpoint runs into the beginning or end of the document.

RemoveFromSelection()

Removes a highlighted section of text, corresponding to the caller's TextPatternRangeEndpoint.Start and TextPatternRangeEndpoint.End endpoints, from the collection of highlighted text in a text container that supports multiple, disjoint selections.

public virtual void RemoveFromSelection()

Exceptions

Type Condition
InvalidOperationException

If text provider does not support multiple, disjoint selections (for example, TextPattern.SupportedTextSelection must have a value of Multiple).

ScrollIntoView(bool)

Causes the text control to scroll vertically until the text range is visible in the viewport.

public virtual void ScrollIntoView(bool alignToTop)
Parameter Type Description
alignToTop bool

true if the text control should be scrolled so the text range is flush with the top of the viewport; false if it should be flush with the bottom of the viewport.

Select()

Selects this instance.

public virtual void Select()

Inherited Members