Table of Contents

Class CodeDocument

Namespace
CodeEdit.Maui
Assembly
CodeEdit.Maui.dll

A live plain-source document with atomic edits, snapshots, and document-owned history.

public sealed class CodeDocument : INotifyPropertyChanged
Inheritance
CodeDocument
Implements
Inherited Members

Remarks

CRLF, LF, and CR line endings are preserved exactly. Attached documents are mutated on the editor's UI thread.

Constructors

CodeDocument(string?)

Creates a source document with empty history and a clean saved state.

public CodeDocument(string? text = null)

Parameters

text string

The initial source, or null for empty source.

Properties

CanRedo

Gets whether redo is available.

public bool CanRedo { get; }

Property Value

bool

CanUndo

Gets whether undo is available.

public bool CanUndo { get; }

Property Value

bool

CurrentSnapshot

Gets an immutable source snapshot suitable for background work.

public CodeDocumentSnapshot CurrentSnapshot { get; }

Property Value

CodeDocumentSnapshot

HistoryByteLimit

Gets or sets the estimated retained-history memory budget.

public long HistoryByteLimit { get; set; }

Property Value

long

HistoryLimit

Gets or sets the maximum retained undo units.

public int HistoryLimit { get; set; }

Property Value

int

IsModified

Gets whether source has changed since the marked saved state.

public bool IsModified { get; }

Property Value

bool

IsUndoGroupOpen

Gets whether an undo group is open.

public bool IsUndoGroupOpen { get; }

Property Value

bool

Length

Gets the UTF-16 source length.

public int Length { get; }

Property Value

int

RedoDescription

Gets the next redo description.

public string? RedoDescription { get; }

Property Value

string

RetainedHistoryByteEstimate

Gets the estimated history storage, excluding application-held snapshots.

public long RetainedHistoryByteEstimate { get; }

Property Value

long

Revision

Gets the opaque source-document revision.

public DocumentRevision Revision { get; }

Property Value

DocumentRevision

Text

Gets the current source text.

public string Text { get; }

Property Value

string

Tracking

Gets source position and range tracking.

public TextTracking Tracking { get; }

Property Value

TextTracking

UndoDescription

Gets the next undo description.

public string? UndoDescription { get; }

Property Value

string

Version

Gets the monotonically increasing content revision.

public long Version { get; }

Property Value

long

Methods

BeginUndoGroup(string?)

Groups separately committed edits into one undo unit.

public IDisposable BeginUndoGroup(string? description = null)

Parameters

description string

The group description.

Returns

IDisposable

A scope disposed in reverse nesting order.

CaptureSave()

Captures an immutable snapshot and its paired state to acknowledge after an asynchronous save succeeds.

public TextSaveCapture CaptureSave()

Returns

TextSaveCapture

The snapshot paired with its save token.

ClearUndoHistory()

Clears history without changing source or its saved state.

public void ClearUndoHistory()

Edit(Action<CodeDocumentEdit>, TextEditOptions)

Applies a transaction of source-only edits.

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

Parameters

edit Action<CodeDocumentEdit>

The transaction callback.

options TextEditOptions

History and application metadata.

Returns

TextDocumentChangedEventArgs

The committed change set.

FromPlainText(string?)

Creates a source document preserving its exact line endings.

public static CodeDocument FromPlainText(string? text)

Parameters

text string

The source text.

Returns

CodeDocument

A new source document.

GetText(TextSpan)

Reads a bounded UTF-16 source range.

public string GetText(TextSpan range)

Parameters

range TextSpan

The range to read.

Returns

string

The source in that range.

MarkSaved()

Marks the current source state as saved.

public void MarkSaved()

MarkSaved(TextSaveCapture)

Marks a captured source state as saved, preserving the dirty state of intervening edits.

public void MarkSaved(TextSaveCapture savePoint)

Parameters

savePoint TextSaveCapture

The successfully saved state.

Redo()

Reapplies the next edit and maps each attached view's selection.

public void Redo()

Undo()

Undoes the preceding edit and maps each attached view's selection.

public void Undo()

Events

Changed

Occurs once after an atomic source edit, with the attached selection already synchronized.

public event EventHandler<TextDocumentChangedEventArgs>? Changed

Event Type

EventHandler<TextDocumentChangedEventArgs>

PropertyChanged

public event PropertyChangedEventHandler? PropertyChanged

Event Type

PropertyChangedEventHandler