INodeKindHandler Interface
Definition
Handles the full lifecycle for a specific Avalonia.Controls.Documents.TextModel.TextDocumentNodeKind: element creation, snapshot capture/restore, and visual node creation. Each registered kind is bound to exactly one handler.
public interface INodeKindHandler
Remarks
Handlers are registered once at startup via Avalonia.Controls.Documents.TextModel.TextDocumentNodeKind.Register(string,Avalonia.Controls.Documents.TextModel.NodeKindFlags,Avalonia.Controls.Documents.TextModel.INodeKindHandler) or by the built-in kind initialization. The correct handler is invoked automatically during snapshot capture, restore, and rendering.
Thread-safety: Avalonia.Controls.Documents.TextModel.INodeKindHandler.CaptureSnapshot(Avalonia.Controls.Documents.TextModel.TextDocumentNodeKind,int,int,Avalonia.Controls.Documents.RichTextElement,Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode,Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNodeChildren) is called on the UI thread during snapshot creation. The Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode it returns is stored on the Avalonia.Controls.Documents.Serialization.Snapshot.DocumentSnapshot and may be read from background threads by serializers. Return only immutable or thread-safe snapshot nodes.
Methods
| Name | Description |
|---|---|
| ApplyFormatting | Applies formatting from a Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode to a restored element. Called during both eager and lazy element materialization from a snapshot. |
| CaptureSnapshot | Creates a Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode from a live document node. Called during Avalonia.Controls.Documents.Serialization.Snapshot.DocumentSnapshot creation on the UI thread. |
| CreateDocumentNode | Creates a Avalonia.Controls.Documents.Primitives.DocumentNodes.DocumentNode visual wrapper for the given element. Called by the rendering layer to wrap model elements in layout/rendering nodes. |
| CreateElement | Creates a new Avalonia.Controls.Documents.RichTextElement instance for the given kind. Called during snapshot restoration (eager and lazy paths) and undo/redo. |
ApplyFormatting Method
Applies formatting from a Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode to a restored element. Called during both eager and lazy element materialization from a snapshot.
public void ApplyFormatting(Avalonia.Controls.Documents.RichTextElement element, Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode snapshotNode)
Parameters
element Avalonia.Controls.Documents.RichTextElement
The element to apply formatting to.
snapshotNode Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode
The snapshot node containing the formatting data.
CaptureSnapshot Method
Creates a Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode from a live document node. Called during Avalonia.Controls.Documents.Serialization.Snapshot.DocumentSnapshot creation on the UI thread.
public Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode CaptureSnapshot(Avalonia.Controls.Documents.TextModel.TextDocumentNodeKind kind, int startOffset, int length, Avalonia.Controls.Documents.RichTextElement element, Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode deferredSnapshot, Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNodeChildren children)
Parameters
kind Avalonia.Controls.Documents.TextModel.TextDocumentNodeKind
The kind of the document node.
startOffset int
The absolute start offset of the node in the document text.
length int
The length of the node's content in characters.
element Avalonia.Controls.Documents.RichTextElement
The element attached to the node, or null if the element
has not been materialized (deferred snapshot path).
deferredSnapshot Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode
The previously captured snapshot for this node when the element was never
realized (deferred path), or null on the normal capture path.
When non-null, formatting should be seeded from this snapshot.
children Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNodeChildren
Pre-captured child snapshot nodes.
Returns
Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode
An immutable snapshot node capturing all kind-specific state.
CreateDocumentNode Method
Creates a Avalonia.Controls.Documents.Primitives.DocumentNodes.DocumentNode visual wrapper for the given element. Called by the rendering layer to wrap model elements in layout/rendering nodes.
public Avalonia.Controls.Documents.Primitives.DocumentNodes.DocumentNode CreateDocumentNode(Avalonia.Controls.Documents.RichTextElement element)
Parameters
element Avalonia.Controls.Documents.RichTextElement
The rich text element to wrap.
Returns
Avalonia.Controls.Documents.Primitives.DocumentNodes.DocumentNode
A new Avalonia.Controls.Documents.Primitives.DocumentNodes.DocumentNode, or null for inline-only kinds
that render inside their parent's text layout (Run, Span, Bold, etc.).
CreateElement Method
Creates a new Avalonia.Controls.Documents.RichTextElement instance for the given kind. Called during snapshot restoration (eager and lazy paths) and undo/redo.
public Avalonia.Controls.Documents.RichTextElement CreateElement(Avalonia.Controls.Documents.TextModel.TextDocumentNodeKind kind)
Parameters
kind Avalonia.Controls.Documents.TextModel.TextDocumentNodeKind
The node kind to create an element for.
Returns
Avalonia.Controls.Documents.RichTextElement
A new element instance, or null if the kind is not handled.