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
textstringThe initial source, or null for empty source.
Properties
CanRedo
Gets whether redo is available.
public bool CanRedo { get; }
Property Value
CanUndo
Gets whether undo is available.
public bool CanUndo { get; }
Property Value
CurrentSnapshot
Gets an immutable source snapshot suitable for background work.
public CodeDocumentSnapshot CurrentSnapshot { get; }
Property Value
HistoryByteLimit
Gets or sets the estimated retained-history memory budget.
public long HistoryByteLimit { get; set; }
Property Value
HistoryLimit
Gets or sets the maximum retained undo units.
public int HistoryLimit { get; set; }
Property Value
IsModified
Gets whether source has changed since the marked saved state.
public bool IsModified { get; }
Property Value
IsUndoGroupOpen
Gets whether an undo group is open.
public bool IsUndoGroupOpen { get; }
Property Value
Length
Gets the UTF-16 source length.
public int Length { get; }
Property Value
RedoDescription
Gets the next redo description.
public string? RedoDescription { get; }
Property Value
RetainedHistoryByteEstimate
Gets the estimated history storage, excluding application-held snapshots.
public long RetainedHistoryByteEstimate { get; }
Property Value
Revision
Gets the opaque source-document revision.
public DocumentRevision Revision { get; }
Property Value
Text
Gets the current source text.
public string Text { get; }
Property Value
Tracking
Gets source position and range tracking.
public TextTracking Tracking { get; }
Property Value
UndoDescription
Gets the next undo description.
public string? UndoDescription { get; }
Property Value
Version
Gets the monotonically increasing content revision.
public long Version { get; }
Property Value
Methods
BeginUndoGroup(string?)
Groups separately committed edits into one undo unit.
public IDisposable BeginUndoGroup(string? description = null)
Parameters
descriptionstringThe 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
editAction<CodeDocumentEdit>The transaction callback.
optionsTextEditOptionsHistory 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
textstringThe source text.
Returns
- CodeDocument
A new source document.
GetText(TextSpan)
Reads a bounded UTF-16 source range.
public string GetText(TextSpan range)
Parameters
rangeTextSpanThe 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
savePointTextSaveCaptureThe 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
PropertyChanged
public event PropertyChangedEventHandler? PropertyChanged