TextSelection Class
Definition
Represents a text selection within a document. Manages selection state with anchor and moving positions for intuitive selection extension.
public class TextSelection
Remarks
Inherits from Avalonia.Controls.Documents.TextModel.TextRange to share formatting and content operations.
Constructors
| Name | Description |
|---|---|
| TextSelection | Initializes a new instance of the Avalonia.Controls.TextSelection class. |
TextSelection Constructor
Initializes a new instance of the Avalonia.Controls.TextSelection class.
public TextSelection(Avalonia.Controls.Documents.TextModel.TextDocument document)
Parameters
document Avalonia.Controls.Documents.TextModel.TextDocument
The text document containing the selection.
Methods
| Name | Description |
|---|---|
| ApplyPropertyValue | No summary available. |
| ClearAllProperties | Clears all inline formatting properties from the range. Content is preserved; only formatting is removed. Produces a single Avalonia.Controls.Documents.Undo.BlockSnapshotUndoUnit for atomic undo/redo. Inherited from TextRange. |
| ClearPropertyValue | Inherited from TextRange. |
| ClearSelection | Clears the selection, placing the caret at the current caret position. |
| ClearSpringloadProperties | Clears all springloaded properties. |
| ClearSpringloadProperty | Clears a springloaded property. |
| Contains (2 overloads) | Checks if the range contains the specified pointer. Inherited from TextRange. |
| CreateSnapshot | Creates an immutable, thread-safe snapshot of this range's document structure. The caller chooses a serializer to convert the snapshot to a specific format. Inherited from TextRange. |
| Delete | Deletes the selected content, then collapses the selection to the deletion point and resets direction. |
| DeleteCurrentBlock (2 overloads) | Deletes the block this range starts in, and collapses the range onto the deletion point. Inherited from TextRange. |
| DeleteText | Deletes the content of this range. Removes whatever the range covers — characters, inline runs, paragraphs, list items, tables, sections — depending on which nodes the range fully encloses. When the deletion crosses block boundaries and both surviving boundary blocks are paragraphs, mergeBlocks controls whether the surviving fragments fuse into one paragraph. Manages transaction automatically. Inherited from TextRange. |
| DeleteTextAt | Deletes text at the specified range relative to this range. Manages transaction automatically. Inherited from TextRange. |
| ExtendTo | Extends the selection to a new position while keeping the anchor fixed. |
| GetContainingBlock | No summary available. |
| GetPropertyValue | Inherited from TextRange. |
| GetSpringloadProperties | Gets all springloaded properties. |
| GetText | Returns the text content covered by this range. Inherited from TextRange. |
| InsertFootnote | Replaces the range content with a footnote: the anchor (its number as ordinary text) lands at the range position, splitting a run when it sits mid-run, and the note body is created in the document's trailing footnote container with a fresh id - selection delete, anchor, body, and the anchor renumbering are one undo unit. Manages transaction automatically. Inherited from TextRange. |
| InsertImage | Inherited from TextRange. |
| InsertPageNumberField | Replaces the range content with a page-number field of kind: the field lands at the range position, splitting a run when it sits mid-run, and shows its cached result until a page layout resolves it (a band on a sheet renders the sheet's number) - selection delete and insertion are one undo unit. Manages transaction automatically. Inherited from TextRange. |
| InsertSnapshot | Inserts a document snapshot over the selection, then collapses the selection to the end of the inserted content and resets direction. |
| InsertTextAt | Inserts text at the specified offset relative to the range start. Manages transaction automatically. Inherited from TextRange. |
| Load | Replaces this range with the content of a stream. Inherited from TextRange. |
| MoveTo | Moves the caret to the specified position. |
| Overlaps | Checks if this range overlaps with another range. Inherited from TextRange. |
| ReplaceText (2 overloads) | Inherited from TextRange. |
| ReplaceTextAt | Replaces text at the specified range relative to this range. Manages transaction automatically. Inherited from TextRange. |
| Save | Writes this range to a stream. Inherited from TextRange. |
| Select | Selects a range of text between two positions. |
| SelectAll | Selects all content in the document, from Avalonia.Controls.Documents.TextModel.TextDocument.ContentStart to Avalonia.Controls.Documents.TextModel.TextDocument.ContentEnd. ContentEnd anchors to the document's final block, so a trailing empty paragraph is part of the selection (and survives copy). |
| SetImageAltText | Sets the alternative text of an existing Avalonia.Controls.Documents.RichImage in a single undoable change. Inherited from TextRange. |
| SetImageSize | Sets the display size of an existing Avalonia.Controls.Documents.RichImage in a single undoable change. Pass double.NaN for a dimension to use the image's intrinsic pixel size. Inherited from TextRange. |
| SetSpringloadProperty | No summary available. |
| TogglePropertyValue | No summary available. |
| ToString | Inherited from TextRange. |
| TryGetPropertyValue | Inherited from TextRange. |
| TryGetSpringloadProperty | No summary available. |
ApplyPropertyValue Method
public void ApplyPropertyValue<T>(Avalonia.StyledProperty<T> property, T value)
Parameters
property Avalonia.StyledProperty<T>
value T
Type Parameters
T
ClearSelection Method
Clears the selection, placing the caret at the current caret position.
public void ClearSelection()
ClearSpringloadProperties Method
Clears all springloaded properties.
public void ClearSpringloadProperties()
ClearSpringloadProperty Method
Clears a springloaded property.
public void ClearSpringloadProperty(Avalonia.AvaloniaProperty property)
Parameters
property Avalonia.AvaloniaProperty
The property to clear.
Delete Method
Deletes the selected content, then collapses the selection to the deletion point and resets direction.
public Avalonia.Controls.Documents.TextModel.TextPointer Delete()
Returns
Avalonia.Controls.Documents.TextModel.TextPointer
The deletion-point pointer returned by the base operation.
Remarks
The base Avalonia.Controls.Documents.TextModel.TextRange.Delete returns the deletion point but
does not reset _isForwardSelection or re-anchor the selection, so
cut used to resolve the caret to the wrong endpoint. Re-selecting the
returned pointer fixes every delete/cut entry point.
ExtendTo Method
Extends the selection to a new position while keeping the anchor fixed.
public void ExtendTo(Avalonia.Controls.Documents.TextModel.TextPointer position)
Parameters
position Avalonia.Controls.Documents.TextModel.TextPointer
The new moving position.
GetContainingBlock Method
public Avalonia.Controls.Documents.Block GetContainingBlock()
Returns
GetSpringloadProperties Method
Gets all springloaded properties.
public System.Collections.Generic.IReadOnlyDictionary<Avalonia.AvaloniaProperty, object> GetSpringloadProperties()
Returns
System.Collections.Generic.IReadOnlyDictionary<Avalonia.AvaloniaProperty, object>
A read-only view of springloaded properties.
InsertSnapshot Method
Inserts a document snapshot over the selection, then collapses the selection to the end of the inserted content and resets direction.
public void InsertSnapshot(Avalonia.Controls.Documents.Serialization.Snapshot.DocumentSnapshot snapshot)
Parameters
snapshot Avalonia.Controls.Documents.Serialization.Snapshot.DocumentSnapshot
The snapshot whose tree is grafted into the selection.
Remarks
The base Avalonia.Controls.Documents.TextModel.TextRange.InsertSnapshot(Avalonia.Controls.Documents.Serialization.Snapshot.DocumentSnapshot) leaves the range spanning the grafted content and never touches selection direction, so paste used to leave a non-collapsed selection whose caret sat one line past the content. Collapsing here re-anchors the caret the same way keyboard edits do via Avalonia.Controls.TextSelection.MoveTo(Avalonia.Controls.Documents.TextModel.TextPointer,bool), fixing every paste entry point (toolbar actions and keyboard).
MoveTo Method
Moves the caret to the specified position.
public void MoveTo(Avalonia.Controls.Documents.TextModel.TextPointer position, bool extendSelection)
Parameters
position Avalonia.Controls.Documents.TextModel.TextPointer
The new caret position.
extendSelection bool
If true, extends selection from anchor to the new position. If false, clears selection and moves both anchor and caret.
Select Method
Selects a range of text between two positions.
public void Select(Avalonia.Controls.Documents.TextModel.TextPointer anchor, Avalonia.Controls.Documents.TextModel.TextPointer moving)
Parameters
anchor Avalonia.Controls.Documents.TextModel.TextPointer
The anchor position where the selection starts.
moving Avalonia.Controls.Documents.TextModel.TextPointer
The moving end position that follows user input.
SelectAll Method
Selects all content in the document, from Avalonia.Controls.Documents.TextModel.TextDocument.ContentStart
to Avalonia.Controls.Documents.TextModel.TextDocument.ContentEnd. ContentEnd anchors to the
document's final block, so a trailing empty paragraph is part of the
selection (and survives copy).
public void SelectAll()
SetSpringloadProperty Method
public void SetSpringloadProperty<T>(Avalonia.StyledProperty<T> property, T value)
Parameters
property Avalonia.StyledProperty<T>
value T
Type Parameters
T
TogglePropertyValue Method
public void TogglePropertyValue<T>(Avalonia.StyledProperty<T> property, T onValue, T offValue)
Parameters
property Avalonia.StyledProperty<T>
onValue T
offValue T
Type Parameters
T
TryGetSpringloadProperty Method
public bool TryGetSpringloadProperty<T>(Avalonia.StyledProperty<T> property, T& value)
Parameters
property Avalonia.StyledProperty<T>
value T&
Type Parameters
T
Returns
bool
Properties
| Name | Description |
|---|---|
| AnchorPosition | Gets the anchor position where the selection started. |
| CaretPosition | Gets the caret position (the moving end that follows user input during selection). |
| End | Gets the end position of the range. Inherited from TextRange. |
| IsEmpty | Gets a value indicating whether the range is empty. A range is empty only when Avalonia.Controls.Documents.TextModel.TextRange.Start and Avalonia.Controls.Documents.TextModel.TextRange.End refer to the exact same document position (node-aware). Two distinct positions that happen to share the same integer offset — for example pointers into consecutive empty paragraphs — are not considered empty. Inherited from TextRange. |
| Length | Gets the length of the range in characters. Inherited from TextRange. |
| Start | Gets the start position of the range. Inherited from TextRange. |
| TextDocument | Gets the document containing this range. Inherited from TextRange. |
AnchorPosition Property
Gets the anchor position where the selection started.
public Avalonia.Controls.Documents.TextModel.TextPointer AnchorPosition { get; set; }
CaretPosition Property
Gets the caret position (the moving end that follows user input during selection).
public Avalonia.Controls.Documents.TextModel.TextPointer CaretPosition { get; set; }