Table of Contents

Class TextDocument

Namespace
TextEdit.Core
Assembly
TextEdit.Core.dll

An independent plain-text document with persistent snapshots, atomic edits, shared sessions, and one history.

public sealed class TextDocument
Inheritance
TextDocument
Inherited Members

Remarks

Preserves every UTF-16 code unit and line ending. The first mutation or attached session claims a mutation thread; immutable snapshots may be read on any thread.

Constructors

TextDocument(string)

Creates an independent source document without normalizing input.

public TextDocument(string text = "")

Parameters

text string

TextDocument(TextSnapshot)

Adopts immutable text into a new document identity and clean history.

public TextDocument(TextSnapshot snapshot)

Parameters

snapshot TextSnapshot

Properties

CanRedo

Gets whether document redo is available.

public bool CanRedo { get; }

Property Value

bool

CanUndo

Gets whether document undo is available.

public bool CanUndo { get; }

Property Value

bool

CurrentSnapshot

Gets an immutable snapshot suitable for background reads.

public TextSnapshot CurrentSnapshot { get; }

Property Value

TextSnapshot

HistoryByteLimit

Gets or sets the retained-history byte estimate limit, applied when complete history units are stored.

public long HistoryByteLimit { get; set; }

Property Value

long

HistoryLimit

Gets or sets the maximum retained undo units. Zero disables history retention.

public int HistoryLimit { get; set; }

Property Value

int

IsModified

Gets whether the current content state differs from the acknowledged save.

public bool IsModified { get; }

Property Value

bool

IsUndoGroupOpen

Gets whether an explicit history group is open.

public bool IsUndoGroupOpen { get; }

Property Value

bool

Length

Gets source length in UTF-16 code units.

public int Length { get; }

Property Value

int

RedoDescription

Gets the next redo description.

public string? RedoDescription { get; }

Property Value

string

RetainedHistoryByteEstimate

Gets an estimate of text and tree-path storage retained by undo and redo. Application-held snapshots are excluded.

public long RetainedHistoryByteEstimate { get; }

Property Value

long

Revision

Gets the current document identity and monotonically increasing version.

public DocumentRevision Revision { get; }

Property Value

DocumentRevision

Text

Materializes the complete source text.

public string Text { get; }

Property Value

string

Tracking

Gets indexed positions and ranges owned by this document.

public TextTracking Tracking { get; }

Property Value

TextTracking

UndoDescription

Gets the next undo description.

public string? UndoDescription { get; }

Property Value

string

Methods

BeginUndoGroup(string?)

Groups separately published transactions into one undo unit. Nested scopes must close in reverse order.

public IDisposable BeginUndoGroup(string? description = null)

Parameters

description string

Returns

IDisposable

CaptureSave()

Captures one immutable snapshot and its paired save token. Active composition must finish first.

public TextSaveCapture CaptureSave()

Returns

TextSaveCapture

ClearHistory()

Clears undo and redo without changing source or saved-state identity.

public void ClearHistory()

CreateSession()

Creates an independent view session over this document.

public TextEditorSession CreateSession()

Returns

TextEditorSession

Edit(Action<TextDocumentEdit>, TextEditOptions)

Commits a sequential transaction. Programmer errors leave the live document unchanged.

public TextDocumentChangedEventArgs? Edit(Action<TextDocumentEdit> edit, TextEditOptions options = default)

Parameters

edit Action<TextDocumentEdit>
options TextEditOptions

Returns

TextDocumentChangedEventArgs

MarkSaved(TextSaveCapture)

Acknowledges a successful save of the captured text, retaining dirty state for newer edits.

public void MarkSaved(TextSaveCapture capture)

Parameters

capture TextSaveCapture

Redo()

Reapplies the next content state and maps every session's current selection.

public void Redo()

TryEdit(DocumentRevision, Action<TextDocumentEdit>, TextEditOptions)

Commits only if the supplied document revision is current.

public TextEditResult TryEdit(DocumentRevision expectedRevision, Action<TextDocumentEdit> edit, TextEditOptions options = default)

Parameters

expectedRevision DocumentRevision
edit Action<TextDocumentEdit>
options TextEditOptions

Returns

TextEditResult

Undo()

Restores the preceding content state and maps every session's current selection.

public void Undo()

Events

Changed

Occurs after all session selections have been synchronized.

public event EventHandler<TextDocumentChangedEventArgs>? Changed

Event Type

EventHandler<TextDocumentChangedEventArgs>

StateChanged

Occurs when history availability or saved state changes without changing text.

public event EventHandler? StateChanged

Event Type

EventHandler