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
The ITextDocument for which this snapshot applies.
FooterText
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
Indicates whether there is content in the snapshot.
bool HasContent { get; }
Property Value
- bool:
trueif there is content in the snapshot; otherwise,false.
Remarks
This property simply checks whether the snapshot has a length greater than 0.
HasUniformLineTerminators
Whether only a single kind of line terminator is present in the snapshot text.
bool HasUniformLineTerminators { get; }
Property Value
Remarks
Empty documents are considered to have uniform line terminators.
HeaderText
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
InferredLineTerminator
Returns the LineTerminator inferred for usage based on the snapshot text, falling back to the default LineTerminator used in the .NET environment as needed.
LineTerminator InferredLineTerminator { get; }
Property Value
Remarks
When an environment fallback is required, the NewLine property is examined to determine the appropriate LineTerminator value.
this[int]
A character in the snapshot.
char this[int index] { get; }
| Parameter | Type | Description |
|---|---|---|
| index | int | The index of the character to return. |
Property Value
Length
The number of characters in the snapshot.
Lines
The collection of ITextSnapshotLine objects, each of which represents a line in the snapshot.
SnapshotRange
A TextSnapshotRange that contains the entire text snapshot.
Text
The entire text of the snapshot, with preserved line terminators.
string Text { get; }
Property Value
Remarks
The GetText(LineTerminator?) method can be used to obtain text with normalized line terminators.
Version
The ITextVersion that specifies the text version represented by the snapshot.
Methods
CreateTextChange(ITextChangeType, ITextChangeOptions?)
Creates an ITextChange based on this snapshot, whereby any following calls to methods such as ITextChange.ReplaceText(int, int, string) are grouped into the text change as operations and sequentially executed upon a ITextChange.Apply() call.
ITextChange CreateTextChange(ITextChangeType type, ITextChangeOptions? options = null)
| Parameter | Type | Description |
|---|---|---|
| type | ITextChangeType | An ITextChangeType specifying the type of change. |
| options | ITextChangeOptions | The optional 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, int, bool)
Performs a find next operation.
ISearchResultSet FindNext(ISearchOptions options, int startOffset, bool canWrap)
| Parameter | Type | Description |
|---|---|---|
| options | ISearchOptions | The ISearchOptions to use. |
| startOffset | int | The offset at which to start the search. |
| canWrap | bool | 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, int, bool, 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 | int | The offset at which to start the search. |
| canWrap | bool | 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, int, bool, 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 | int | The offset at which to start the search. |
| canWrap | bool | 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
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 initialize the reader. |
Returns
GetReader(int)
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 | int | The offset at which to initialize the reader. |
Returns
GetSubstring(TextRange, LineTerminator?)
Returns a substring from the snapshot text, optionally normalizing line ends with the specified LineTerminator.
string GetSubstring(TextRange textRange, LineTerminator? lineTerminator = null)
| Parameter | Type | Description |
|---|---|---|
| textRange | TextRange | A TextRange indicating the range of text to retrieve. |
| lineTerminator | LineTerminator? | An optional LineTerminator that when specified, will normalize line ends to use that kind of line terminator.
If left its default value of |
Returns
GetSubstring(int, int, LineTerminator?)
Returns a substring from the snapshot text, optionally normalizing line ends with the specified LineTerminator.
string GetSubstring(int offset, int length, LineTerminator? lineTerminator = null)
| Parameter | Type | Description |
|---|---|---|
| offset | int | The offset at which to retrieve the text. |
| length | int | The number of characters to return. |
| lineTerminator | LineTerminator? | An optional LineTerminator that when specified, will normalize line ends to use that kind of line terminator.
If left its default value of |
Returns
GetText(LineTerminator?)
Returns the entire text of the snapshot, optionally normalizing line ends with the specified LineTerminator.
string GetText(LineTerminator? lineTerminator = null)
| Parameter | Type | Description |
|---|---|---|
| lineTerminator | LineTerminator? | An optional LineTerminator that when specified, will normalize line ends to use that kind of line terminator.
If left its default value of |
Returns
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.
GetWordText(int)
Returns the text of the word at the specified offset.
GetWordText(int, TextOffsetAffinity)
Returns the text of the word at the specified offset.
string GetWordText(int offset, TextOffsetAffinity affinity)
| Parameter | Type | Description |
|---|---|---|
| offset | int | The offset to examine. |
| affinity | TextOffsetAffinity | The TextOffsetAffinity to use. |
Returns
GetWordTextRange(int)
Returns a TextRange of offsets that contain the word at the specified offset.
TextRange GetWordTextRange(int offset)
| Parameter | Type | Description |
|---|---|---|
| offset | int | The offset to examine. |
Returns
GetWordTextRange(int, TextOffsetAffinity)
Returns a TextRange of offsets that contain the word at the specified offset.
TextRange GetWordTextRange(int offset, TextOffsetAffinity affinity)
| Parameter | Type | Description |
|---|---|---|
| offset | int | The offset to examine. |
| affinity | TextOffsetAffinity | The TextOffsetAffinity to use. |
Returns
OffsetToPosition(int)
Returns the TextPosition that represents the specified offset within the text lines.
TextPosition OffsetToPosition(int offset)
| Parameter | Type | Description |
|---|---|---|
| offset | int | The offset of a character within the snapshot. |
Returns
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
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
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. |