Class TextSnapshot
- Namespace
- TextEdit.Core
- Assembly
- TextEdit.Core.dll
An immutable text snapshot backed by a persistent balanced tree of bounded chunks.
public sealed class TextSnapshot
- Inheritance
-
TextSnapshot
- Inherited Members
Remarks
CRLF, CR, LF, and all other UTF-16 data are preserved exactly. Ordinary replacement shares unchanged tree nodes.
Properties
Empty
Gets an empty snapshot with one empty line.
public static TextSnapshot Empty { get; }
Property Value
this[int]
Reads one UTF-16 code unit.
public char this[int position] { get; }
Parameters
positionint
Property Value
Length
Gets the number of UTF-16 code units.
public int Length { get; }
Property Value
LineCount
Gets the logical line count, including an empty final line after a terminator.
public int LineCount { get; }
Property Value
Revision
Gets the owning document revision, or an invalid revision for standalone text.
public DocumentRevision Revision { get; }
Property Value
Methods
Concat(TextSnapshot)
Concatenates immutable text roots without materializing their contents. The result has no document revision.
public TextSnapshot Concat(TextSnapshot next)
Parameters
nextTextSnapshot
Returns
FromText(string)
Creates a snapshot without normalizing text or line endings.
public static TextSnapshot FromText(string text)
Parameters
textstring
Returns
GetChunks(TextSpan)
Enumerates immutable memory segments without materializing the requested text.
public IEnumerable<ReadOnlyMemory<char>> GetChunks(TextSpan range)
Parameters
rangeTextSpan
Returns
GetLine(int)
Gets a zero-based line and its original line terminator length.
public TextLine GetLine(int line)
Parameters
lineint
Returns
GetLines()
Enumerates logical lines in one forward pass without materializing the complete text.
public IEnumerable<TextLine> GetLines()
Returns
GetOffset(TextPosition)
Converts a logical position to an exact UTF-16 offset, including positions within CRLF.
public int GetOffset(TextPosition position)
Parameters
positionTextPosition
Returns
GetPosition(int)
Converts a bounded UTF-16 offset to a zero-based logical position.
public TextPosition GetPosition(int offset)
Parameters
offsetint
Returns
GetText(TextSpan)
Materializes only the requested range.
public string GetText(TextSpan range)
Parameters
rangeTextSpan
Returns
Replace(TextSpan, string)
Returns a new snapshot with the bounded range replaced. An identical replacement returns this snapshot.
public TextSnapshot Replace(TextSpan range, string text)
Parameters
Returns
Slice(TextSpan)
Shares the tree covering a bounded range.
public TextSnapshot Slice(TextSpan range)
Parameters
rangeTextSpan
Returns
ToString()
Materializes the complete text. The optional weak cache does not retain full strings through history.
public override string ToString()
Returns
WriteTo(TextWriter)
Streams the snapshot to a caller-owned writer.
public void WriteTo(TextWriter writer)
Parameters
writerTextWriter