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
textstring
TextDocument(TextSnapshot)
Adopts immutable text into a new document identity and clean history.
public TextDocument(TextSnapshot snapshot)
Parameters
snapshotTextSnapshot
Properties
CanRedo
Gets whether document redo is available.
public bool CanRedo { get; }
Property Value
CanUndo
Gets whether document undo is available.
public bool CanUndo { get; }
Property Value
CurrentSnapshot
Gets an immutable snapshot suitable for background reads.
public TextSnapshot CurrentSnapshot { get; }
Property Value
HistoryByteLimit
Gets or sets the retained-history byte estimate limit, applied when complete history units are stored.
public long HistoryByteLimit { get; set; }
Property Value
HistoryLimit
Gets or sets the maximum retained undo units. Zero disables history retention.
public int HistoryLimit { get; set; }
Property Value
IsModified
Gets whether the current content state differs from the acknowledged save.
public bool IsModified { get; }
Property Value
IsUndoGroupOpen
Gets whether an explicit history group is open.
public bool IsUndoGroupOpen { get; }
Property Value
Length
Gets source length in UTF-16 code units.
public int Length { get; }
Property Value
RedoDescription
Gets the next redo description.
public string? RedoDescription { get; }
Property Value
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
Revision
Gets the current document identity and monotonically increasing version.
public DocumentRevision Revision { get; }
Property Value
Text
Materializes the complete source text.
public string Text { get; }
Property Value
Tracking
Gets indexed positions and ranges owned by this document.
public TextTracking Tracking { get; }
Property Value
UndoDescription
Gets the next undo description.
public string? UndoDescription { get; }
Property Value
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
descriptionstring
Returns
CaptureSave()
Captures one immutable snapshot and its paired save token. Active composition must finish first.
public TextSaveCapture CaptureSave()
Returns
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
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
editAction<TextDocumentEdit>optionsTextEditOptions
Returns
MarkSaved(TextSaveCapture)
Acknowledges a successful save of the captured text, retaining dirty state for newer edits.
public void MarkSaved(TextSaveCapture capture)
Parameters
captureTextSaveCapture
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
expectedRevisionDocumentRevisioneditAction<TextDocumentEdit>optionsTextEditOptions
Returns
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
StateChanged
Occurs when history availability or saved state changes without changing text.
public event EventHandler? StateChanged