Table of Contents

Class RichTextDocument

Namespace
RichEdit.Maui
Assembly
RichEdit.Maui.dll

Represents a stable, observable rich-text document that supports atomic range edits.

public sealed class RichTextDocument : INotifyPropertyChanged
Inheritance
RichTextDocument
Implements
Inherited Members

Constructors

RichTextDocument()

Initializes an empty rich-text document.

public RichTextDocument()

Fields

ObjectReplacementCharacter

The object-replacement character used to reserve a logical text position for an inline object.

public const char ObjectReplacementCharacter = ''

Field Value

char

SoftLineBreakCharacter

The Unicode line-separator character used for a soft line break.

public const char SoftLineBreakCharacter = '\u2028'

Field Value

char

Properties

CanRedo

Gets whether an undone edit can be reapplied.

public bool CanRedo { get; }

Property Value

bool

CanUndo

Gets whether a recorded edit can be undone.

public bool CanUndo { get; }

Property Value

bool

CurrentSnapshot

Gets the immutable snapshot for the current document version.

public RichTextDocumentSnapshot CurrentSnapshot { get; }

Property Value

RichTextDocumentSnapshot

DefaultCharacterFormat

Gets the declared default character format.

public RichTextCharacterFormat DefaultCharacterFormat { get; }

Property Value

RichTextCharacterFormat

DefaultParagraphFormat

Gets the declared default paragraph format.

public RichTextParagraphFormat DefaultParagraphFormat { get; }

Property Value

RichTextParagraphFormat

IsModified

Gets whether the current content differs from the last marked saved state.

public bool IsModified { get; }

Property Value

bool

IsUndoGroupOpen

Gets whether an explicit undo group is open.

public bool IsUndoGroupOpen { get; }

Property Value

bool

Length

Gets the number of UTF-16 code units in the logical text.

public int Length { get; }

Property Value

int

RedoDescription

Gets the description of the next redo operation.

public string? RedoDescription { get; }

Property Value

string

Revision

Gets the current document identity and version as an opaque token.

public DocumentRevision Revision { get; }

Property Value

DocumentRevision

RtfText

Gets the canonical RTF representation of the complete document.

public string RtfText { get; }

Property Value

string

Remarks

The value is serialized lazily and cached by Version. View appearance and native theme defaults are never serialized.

Text

Gets the plain-text projection of the document.

public string Text { get; }

Property Value

string

Tracking

Gets the document's position and range tracking service.

public TextTracking Tracking { get; }

Property Value

TextTracking

UndoDescription

Gets the description of the next undo operation.

public string? UndoDescription { get; }

Property Value

string

Version

Gets the monotonically increasing document version.

public long Version { get; }

Property Value

long

Methods

BeginUndoGroup(string?)

Groups subsequent recorded edits into one undo unit.

public IDisposable BeginUndoGroup(string? description = null)

Parameters

description string

An optional description for the outermost undo unit.

Returns

IDisposable

A scope to dispose after the grouped edits.

Remarks

Groups can nest and must be disposed in reverse order. Each edit still commits and notifies independently; this scope is not a rollback transaction. Undo and redo are unavailable until the outermost group closes. History-clearing edits and explicit history clearing are not allowed inside a group.

ClearUndoHistory()

Clears undo and redo without changing content or its saved state.

public void ClearUndoHistory()

CreateSavePoint()

Captures the current content state before saving its snapshot.

public RichTextSavePoint CreateSavePoint()

Returns

RichTextSavePoint

A save point belonging to this document.

Edit(Action<RichTextDocumentEdit>, RichTextEditOptions)

Applies an atomic set of incremental document edits.

public RichTextChangeSet Edit(Action<RichTextDocumentEdit> edit, RichTextEditOptions options = default)

Parameters

edit Action<RichTextDocumentEdit>

A callback that describes the edits in transaction order.

options RichTextEditOptions

Undo and application metadata for the transaction.

Returns

RichTextChangeSet

The committed change set, or an empty change set when no edit was made.

Exceptions

ArgumentNullException

edit is null.

InvalidOperationException

The callback attempts to start another mutation on the same document.

FromPlainText(string?)

Creates a plain-text document with normalized line endings and empty undo history.

public static RichTextDocument FromPlainText(string? text)

Parameters

text string

The initial text, or null for an empty document.

Returns

RichTextDocument

A new live document.

FromRtf(string)

Creates a document by parsing a complete RTF value.

public static RichTextDocument FromRtf(string rtfText)

Parameters

rtfText string

The RTF value to parse.

Returns

RichTextDocument

A new rich-text document containing the parsed content.

Exceptions

ArgumentNullException

rtfText is null.

FormatException

rtfText is not valid supported RTF.

GetCharacterFormat(TextSpan)

Summarizes declared character formatting in a document range.

public RichTextCharacterFormatSummary GetCharacterFormat(TextSpan range)

Parameters

range TextSpan

The range to inspect.

Returns

RichTextCharacterFormatSummary

A character-format summary.

GetParagraphFormat(TextSpan)

Summarizes declared paragraph formatting in a document range.

public RichTextParagraphFormatSummary GetParagraphFormat(TextSpan range)

Parameters

range TextSpan

The range to inspect.

Returns

RichTextParagraphFormatSummary

A paragraph-format summary.

GetText(TextSpan)

Returns the plain text in a bounded document range.

public string GetText(TextSpan range)

Parameters

range TextSpan

The range to read.

Returns

string

The selected plain text.

MarkSaved()

Marks the current document state as saved.

public void MarkSaved()

MarkSaved(RichTextSavePoint)

Marks a captured state as saved without marking intervening edits as saved.

public void MarkSaved(RichTextSavePoint savePoint)

Parameters

savePoint RichTextSavePoint

The state whose corresponding snapshot was successfully saved.

Redo()

Reapplies the next content state and maps every attached view's selection through the change.

public void Redo()

Undo()

Restores preceding content and maps every attached view's selection through the change.

public void Undo()

Events

Changed

Occurs after an atomic document transaction is committed.

public event EventHandler<RichTextDocumentChangedEventArgs>? Changed

Event Type

EventHandler<RichTextDocumentChangedEventArgs>

PropertyChanged

public event PropertyChangedEventHandler? PropertyChanged

Event Type

PropertyChangedEventHandler