ITextSnapshot Interface
Provides the base requirements for an immutable snapshot of an ITextDocument for a certain ITextVersion of that document.
public interface ITextSnapshot : ITextRangeProvider
Properties
Document
Gets the ITextDocument for which this snapshot applies.
ITextDocument Document { get; }
Property Value
- ITextDocument:
The ITextDocument for which this snapshot applies.
FooterText
Gets the footer text to append to the end of the snapshot's Text when scanning through the GetMergedBufferReader() result, typically used when parsing the snapshot.
string FooterText { get; }
Property Value
Remarks
The use of this property, along with HeaderText, allows for editing 'fragments' of code.
The header and footer sections provide the outer code that surrounds the
'fragment' being edited in the snapshot's Text property.
An example is when editing a method body in a language like C#
.
The HeaderText would contain the namespace, class, and member declaration starts.
The FooterText would contain the namespace, class, and member declaration ends.
The document would edit the 'fragment' of statements within the header and footer, and
all of them would be combined for parsing purposes.
See Also
HasContent
Gets whether there is content in the snapshot.
bool HasContent { get; }
Property Value
- Boolean:
true
if there is content in the snapshot; otherwise,false
.
Remarks
This property simply checks whether the snapshot has a length greater than 0
.
HeaderText
Gets the header text to append to the start of the snapshot's Text when scanning through the GetMergedBufferReader() result, typically used when parsing the snapshot.
string HeaderText { get; }
Property Value
Remarks
The use of this property, along with FooterText, allows for editing 'fragments' of code.
The header and footer sections provide the outer code that surrounds the
'fragment' being edited in the snapshot's Text property.
An example is when editing a method body in a language like C#
.
The HeaderText would contain the namespace, class, and member declaration starts.
The FooterText would contain the namespace, class, and member declaration ends.
The document would edit the 'fragment' of statements within the header and footer, and
all of them would be combined for parsing purposes.
See Also
Item[Int32]
Gets a character in the snapshot.
char this[int index] { get; }
Parameter | Type | Description |
---|---|---|
index | Int32 | The index of the character to return. |
Property Value
- Char:
A character in the snapshot.
Length
Gets the number of characters in the snapshot, excluding any carriage-returns but including newlines.
int Length { get; }
Property Value
- Int32:
The number of characters in the snapshot, excluding any carriage-returns but including newlines.
Lines
Gets the collection of ITextSnapshotLine objects, each of which represents a line in the snapshot.
ITextSnapshotLineCollection Lines { get; }
Property Value
- ITextSnapshotLineCollection:
A ITextSnapshotLineCollection containing the lines in the snapshot.
SnapshotRange
Gets a TextSnapshotRange that contains the entire text snapshot.
TextSnapshotRange SnapshotRange { get; }
Property Value
- TextSnapshotRange:
A TextSnapshotRange that contains the entire text snapshot.
Text
Gets the entire text of the snapshot using CarriageReturnNewline for line ends, which is not intended to be used for parsing for classification reasons.
string Text { get; }
Property Value
- String:
The entire text of the snapshot using CarriageReturnNewline for line ends.
Remarks
This property should not be used as input for language parsers or taggers since internally for performance reasons, text is stored with newlines-only as line terminators. Instead, call GetText(LineTerminator) with the Newline parameter when needing the text for parsing or tagging reasons.
The GetText(LineTerminator) method can be used to obtain text using any of the LineTerminator options.
Version
Gets the ITextVersion that specifies the text version represented by the snapshot.
ITextVersion Version { get; }
Property Value
- ITextVersion:
The ITextVersion that specifies the text version represented by the snapshot.
Methods
CreateTextChange(ITextChangeType)
Creates an ITextChange based on this snapshot, whereby any following calls to methods such as ITextChange.ReplaceText(Int32, Int32, String) are grouped into the text change as operations and sequentially executed upon a ITextChange.Apply() call.
ITextChange CreateTextChange(ITextChangeType type)
Parameter | Type | Description |
---|---|---|
type | ITextChangeType | An ITextChangeType specifying the type of change. |
Returns
- ITextChange:
The ITextChange that was created.
Remarks
The ITextChange.Apply() method must be called to apply the queued operations to the document.
CreateTextChange(ITextChangeType, ITextChangeOptions)
Creates an ITextChange based on this snapshot, whereby any following calls to methods such as ITextChange.ReplaceText(Int32, Int32, String) are grouped into the text change as operations and sequentially executed upon a ITextChange.Apply() call.
ITextChange CreateTextChange(ITextChangeType type, ITextChangeOptions options)
Parameter | Type | Description |
---|---|---|
type | ITextChangeType | An ITextChangeType specifying the type of change. |
options | ITextChangeOptions | The ITextChangeOptions for the change. |
Returns
- ITextChange:
The ITextChange that was created.
Remarks
The ITextChange.Apply() method must be called to apply the queued operations to the document.
Export(ITextExporter)
Exports the contents of the snapshot to another text format, such as HTML
or RTF
.
string Export(ITextExporter exporter)
Parameter | Type | Description |
---|---|---|
exporter | ITextExporter | The ITextExporter to use for the export operation. |
Returns
- String:
The exported text.
ExportToFile(ITextExporter, String)
Exports the contents of the snapshot to a file in another text format, such as HTML
or RTF
.
void ExportToFile(ITextExporter exporter, string path)
Parameter | Type | Description |
---|---|---|
exporter | ITextExporter | The ITextExporter to use for the export operation. |
path | String | The full path of the file of which to save. |
FindAll(ISearchOptions)
Performs a find all operation.
ISearchResultSet FindAll(ISearchOptions options)
Parameter | Type | Description |
---|---|---|
options | ISearchOptions | The ISearchOptions to use. |
Returns
- ISearchResultSet:
An ISearchResultSet that specifies the result of the operation.
FindAll(ISearchOptions, TextRange)
Performs a find all operation over a specific range of the snapshot.
ISearchResultSet FindAll(ISearchOptions options, TextRange searchTextRange)
Parameter | Type | Description |
---|---|---|
options | ISearchOptions | The ISearchOptions to use. |
searchTextRange | TextRange | The TextRange of offsets to search.
If all should be searched, specify the range |
Returns
- ISearchResultSet:
An ISearchResultSet that specifies the result of the operation.
FindNext(ISearchOptions, Int32, Boolean)
Performs a find next operation.
ISearchResultSet FindNext(ISearchOptions options, int startOffset, bool canWrap)
Parameter | Type | Description |
---|---|---|
options | ISearchOptions | The ISearchOptions to use. |
startOffset | Int32 | The offset at which to start the search. |
canWrap | Boolean | Whether the search can wrap at the end of the search text range. |
Returns
- ISearchResultSet:
An ISearchResultSet that specifies the result of the operation.
FindNext(ISearchOptions, Int32, Boolean, TextRange)
Performs a find next operation over a specific range of the snapshot.
ISearchResultSet FindNext(ISearchOptions options, int startOffset, bool canWrap, TextRange searchTextRange)
Parameter | Type | Description |
---|---|---|
options | ISearchOptions | The ISearchOptions to use. |
startOffset | Int32 | The offset at which to start the search. |
canWrap | Boolean | Whether the search can wrap at the end of the search text range. |
searchTextRange | TextRange | The TextRange of offsets to search.
If all should be searched, specify the range |
Returns
- ISearchResultSet:
An ISearchResultSet that specifies the result of the operation.
FindNext(ISearchOptions, Int32, Boolean, TextRange, CancellationToken)
Performs a find next operation over a specific range of the snapshot.
ISearchResultSet FindNext(ISearchOptions options, int startOffset, bool canWrap, TextRange searchTextRange, CancellationToken cancellationToken)
Parameter | Type | Description |
---|---|---|
options | ISearchOptions | The ISearchOptions to use. |
startOffset | Int32 | The offset at which to start the search. |
canWrap | Boolean | Whether the search can wrap at the end of the search text range. |
searchTextRange | TextRange | The TextRange of offsets to search.
If all should be searched, specify the range |
cancellationToken | CancellationToken | The cancellation token that can abort the search operation. |
Returns
- ISearchResultSet:
An ISearchResultSet that specifies the result of the operation.
GetMergedBufferReader()
Returns an ITextBufferReader that allows scanning over a union of the HeaderText, Text, and FooterText.
ITextBufferReader GetMergedBufferReader()
Returns
- ITextBufferReader:
An ITextBufferReader that allows scanning over a union of the HeaderText, Text, and FooterText.
See Also
GetReader(TextPosition)
Returns an ITextSnapshotReader that can be used to navigate through the text and token contents of the snapshot.
ITextSnapshotReader GetReader(TextPosition position)
Parameter | Type | Description |
---|---|---|
position | TextPosition | The TextPosition at which to initalize the reader. |
Returns
- ITextSnapshotReader:
An ITextSnapshotReader that can be used to navigate through the text and token contents of the snapshot.
GetReader(Int32)
Returns an ITextSnapshotReader that can be used to navigate through the text and token contents of the snapshot.
ITextSnapshotReader GetReader(int offset)
Parameter | Type | Description |
---|---|---|
offset | Int32 | The offset at which to initalize the reader. |
Returns
- ITextSnapshotReader:
An ITextBufferReader that can be used to navigate through the text and token contents of the snapshot.
GetSubstring(TextRange)
Returns a substring from the snapshot text using CarriageReturnNewline for line ends.
string GetSubstring(TextRange textRange)
Parameter | Type | Description |
---|---|---|
textRange | TextRange | A TextRange indicating the range of text to retrieve. |
Returns
- String:
The substring from the snapshot text using CarriageReturnNewline for line ends.
GetSubstring(TextRange, LineTerminator)
Returns a substring from the snapshot text using the specified LineTerminator for line ends.
string GetSubstring(TextRange textRange, LineTerminator lineTerminator)
Parameter | Type | Description |
---|---|---|
textRange | TextRange | A TextRange indicating the range of text to retrieve. |
lineTerminator | LineTerminator | A LineTerminator specifying the type of line terminators to use. |
Returns
- String:
The substring from the snapshot text using the specified LineTerminator for line ends.
GetSubstring(Int32, Int32)
Returns a substring from the snapshot text using CarriageReturnNewline for line ends.
string GetSubstring(int offset, int length)
Parameter | Type | Description |
---|---|---|
offset | Int32 | The offset at which to retrieve the text. |
length | Int32 | The number of characters to return. |
Returns
- String:
The substring from the snapshot text using CarriageReturnNewline for line ends.
GetSubstring(Int32, Int32, LineTerminator)
Returns a substring from the snapshot text using the specified LineTerminator for line ends.
string GetSubstring(int offset, int length, LineTerminator lineTerminator)
Parameter | Type | Description |
---|---|---|
offset | Int32 | The offset at which to retrieve the text. |
length | Int32 | The number of characters to return. |
lineTerminator | LineTerminator | A LineTerminator specifying the type of line terminators to use. |
Returns
- String:
The substring from the snapshot text using the specified LineTerminator for line ends.
GetText(LineTerminator)
Returns the entire text of the snapshot using the specified LineTerminator for line ends.
string GetText(LineTerminator lineTerminator)
Parameter | Type | Description |
---|---|---|
lineTerminator | LineTerminator | A LineTerminator specifying the type of line terminators to use. |
Returns
- String:
The entire text of the snapshot using the specified LineTerminator for line ends.
Remarks
To retrieve the text in the format expected by a language parser or tagger,
pass Newline as the lineTerminator
parameter.
GetTextStatistics()
Returns an ITextStatistics for the snapshot's text, which provides numerous statistics about the text such as word, sentence, character counts as well as readability scores.
ITextStatistics GetTextStatistics()
Returns
- ITextStatistics:
An ITextStatistics for the snapshot's text.
GetWordText(Int32)
Gets the text of the word at the specified offset.
string GetWordText(int offset)
Parameter | Type | Description |
---|---|---|
offset | Int32 | The offset to examine. |
Returns
- String:
The text of the word at the specified offset.
GetWordText(Int32, TextOffsetAffinity)
Gets the text of the word at the specified offset.
string GetWordText(int offset, TextOffsetAffinity affinity)
Parameter | Type | Description |
---|---|---|
offset | Int32 | The offset to examine. |
affinity | TextOffsetAffinity | The TextOffsetAffinity to use. |
Returns
- String:
The text of the word at the specified offset.
GetWordTextRange(Int32)
Gets a TextRange of offsets that contain the word at the specified offset.
TextRange GetWordTextRange(int offset)
Parameter | Type | Description |
---|---|---|
offset | Int32 | The offset to examine. |
Returns
GetWordTextRange(Int32, TextOffsetAffinity)
Gets a TextRange of offsets that contain the word at the specified offset.
TextRange GetWordTextRange(int offset, TextOffsetAffinity affinity)
Parameter | Type | Description |
---|---|---|
offset | Int32 | The offset to examine. |
affinity | TextOffsetAffinity | The TextOffsetAffinity to use. |
Returns
OffsetToPosition(Int32)
Returns the TextPosition that represents the specified offset within the text lines.
TextPosition OffsetToPosition(int offset)
Parameter | Type | Description |
---|---|---|
offset | Int32 | The offset of a character within the snapshot. |
Returns
- TextPosition:
The TextPosition that represents the specified offset within the text lines.
PositionRangeToTextRange(TextPositionRange)
Returns the TextRange that represents the specified TextPositionRange within the snapshot.
TextRange PositionRangeToTextRange(TextPositionRange positionRange)
Parameter | Type | Description |
---|---|---|
positionRange | TextPositionRange | The TextPositionRange within the snapshot. |
Returns
- TextRange:
The TextRange that represents the specified TextPositionRange within the snapshot.
PositionToOffset(TextPosition)
Returns the offset for the specified TextPosition within the text lines.
int PositionToOffset(TextPosition position)
Parameter | Type | Description |
---|---|---|
position | TextPosition | The TextPosition of a character within the text lines. |
Returns
- Int32:
The offset for the specified TextPosition within the text lines.
TextRangeToPositionRange(TextRange)
Returns the TextPositionRange that represents the specified TextRange within the snapshot.
TextPositionRange TextRangeToPositionRange(TextRange textRange)
Parameter | Type | Description |
---|---|---|
textRange | TextRange | The TextRange within the snapshot. |
Returns
- TextPositionRange:
The TextPositionRange that represents the specified TextRange within the snapshot.