SelectionSnapshot Struct
Definition
Value-type snapshot of a Avalonia.Controls.TextSelection captured at a point in time. Stores a frozen Avalonia.Controls.Documents.TextModel.TextPointer per endpoint together with the offset inside that endpoint's cached leaf and the child-index path from the document root down to that leaf.
public struct SelectionSnapshot
Remarks
Restoration uses a three-tier strategy:
- Fast path: if the captured leaf is still attached to the live tree (true for every non-structural edit and for the pre-edit side of a just-replayed structural edit), re-derive the global offset as
Node.GlobalStartOffset + leafOffset. - Path walk: when the captured leaf has been detached (structural Undo/Redo replaces node instances), walk the child-index path from the document root.
MaterializeFromSnapshotpreserves child ordering deterministically, so the path resolves to the correct rematerialized leaf. - Last-resort fallback: offset-based pointer creation.
The leaf offset is frozen at capture time because the leaf's
GlobalStartOffset may shift between capture and restore when
earlier content changes. At restore time the global offset is
re-derived from the (possibly replaced) leaf's current
GlobalStartOffset plus this captured leafOffset.
Methods
| Name | Description |
|---|---|
| Capture | Captures selection's two endpoints. Pass the result to Avalonia.Controls.Documents.Undo.UndoManager.BeginUndoUnit(string,Nullable{Avalonia.Controls.Documents.Undo.SelectionSnapshot}) as the pre-edit state, or to Avalonia.Controls.Documents.Undo.IUndoScope.SetSelectionAfter(Nullable{Avalonia.Controls.Documents.Undo.SelectionSnapshot}) as the post-edit state, to have the caret restored with the unit. |
| Equals (2 overloads) | Returns if this snapshot equals other by reference equality on all components. |
| GetHashCode | No summary available. |
Capture Method
Captures selection's two endpoints. Pass the
result to Avalonia.Controls.Documents.Undo.UndoManager.BeginUndoUnit(string,Nullable{Avalonia.Controls.Documents.Undo.SelectionSnapshot}) as the pre-edit
state, or to Avalonia.Controls.Documents.Undo.IUndoScope.SetSelectionAfter(Nullable{Avalonia.Controls.Documents.Undo.SelectionSnapshot}) as the
post-edit state, to have the caret restored with the unit.
public Avalonia.Controls.Documents.Undo.SelectionSnapshot Capture(Avalonia.Controls.TextSelection selection)
Parameters
selection Avalonia.Controls.TextSelection
The live selection to freeze.
Returns
Avalonia.Controls.Documents.Undo.SelectionSnapshot
A snapshot of the selection's anchor and caret.
Exceptions
Equals overloads
Equals Method
Returns if this snapshot equals other by reference equality on all components.
public bool Equals(Avalonia.Controls.Documents.Undo.SelectionSnapshot other)
Parameters
other Avalonia.Controls.Documents.Undo.SelectionSnapshot
Returns
bool
Equals Method
public bool Equals(object obj)
Parameters
obj object
Returns
bool
GetHashCode Method
public int GetHashCode()
Returns
int
Properties
| Name | Description |
|---|---|
| Anchor | Frozen anchor pointer. Shares its cached leaf with the source selection. |
| AnchorLeafOffset | Offset inside Avalonia.Controls.Documents.Undo.SelectionSnapshot.Anchor's leaf at capture time. |
| IsEmpty | True when the anchor and moving pointers coincide. |
| Moving | Frozen caret / moving pointer. |
| MovingLeafOffset | Offset inside Avalonia.Controls.Documents.Undo.SelectionSnapshot.Moving's leaf at capture time. |
Anchor Property
Frozen anchor pointer. Shares its cached leaf with the source selection.
public Avalonia.Controls.Documents.TextModel.TextPointer Anchor { get; set; }
AnchorLeafOffset Property
Offset inside Avalonia.Controls.Documents.Undo.SelectionSnapshot.Anchor's leaf at capture time.
public int AnchorLeafOffset { get; set; }
IsEmpty Property
True when the anchor and moving pointers coincide.
public bool IsEmpty { get; set; }
Moving Property
Frozen caret / moving pointer.
public Avalonia.Controls.Documents.TextModel.TextPointer Moving { get; set; }
MovingLeafOffset Property
Offset inside Avalonia.Controls.Documents.Undo.SelectionSnapshot.Moving's leaf at capture time.
public int MovingLeafOffset { get; set; }