Table of Contents

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

TextSnapshot

this[int]

Reads one UTF-16 code unit.

public char this[int position] { get; }

Parameters

position int

Property Value

char

Length

Gets the number of UTF-16 code units.

public int Length { get; }

Property Value

int

LineCount

Gets the logical line count, including an empty final line after a terminator.

public int LineCount { get; }

Property Value

int

Revision

Gets the owning document revision, or an invalid revision for standalone text.

public DocumentRevision Revision { get; }

Property Value

DocumentRevision

Methods

Concat(TextSnapshot)

Concatenates immutable text roots without materializing their contents. The result has no document revision.

public TextSnapshot Concat(TextSnapshot next)

Parameters

next TextSnapshot

Returns

TextSnapshot

FromText(string)

Creates a snapshot without normalizing text or line endings.

public static TextSnapshot FromText(string text)

Parameters

text string

Returns

TextSnapshot

GetChunks(TextSpan)

Enumerates immutable memory segments without materializing the requested text.

public IEnumerable<ReadOnlyMemory<char>> GetChunks(TextSpan range)

Parameters

range TextSpan

Returns

IEnumerable<ReadOnlyMemory<char>>

GetLine(int)

Gets a zero-based line and its original line terminator length.

public TextLine GetLine(int line)

Parameters

line int

Returns

TextLine

GetLines()

Enumerates logical lines in one forward pass without materializing the complete text.

public IEnumerable<TextLine> GetLines()

Returns

IEnumerable<TextLine>

GetOffset(TextPosition)

Converts a logical position to an exact UTF-16 offset, including positions within CRLF.

public int GetOffset(TextPosition position)

Parameters

position TextPosition

Returns

int

GetPosition(int)

Converts a bounded UTF-16 offset to a zero-based logical position.

public TextPosition GetPosition(int offset)

Parameters

offset int

Returns

TextPosition

GetText(TextSpan)

Materializes only the requested range.

public string GetText(TextSpan range)

Parameters

range TextSpan

Returns

string

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

range TextSpan
text string

Returns

TextSnapshot

Slice(TextSpan)

Shares the tree covering a bounded range.

public TextSnapshot Slice(TextSpan range)

Parameters

range TextSpan

Returns

TextSnapshot

ToString()

Materializes the complete text. The optional weak cache does not retain full strings through history.

public override string ToString()

Returns

string

WriteTo(TextWriter)

Streams the snapshot to a caller-owned writer.

public void WriteTo(TextWriter writer)

Parameters

writer TextWriter