ITextView Interface
Definition
Provides coordinate mapping and hit testing for document content. Bridges between the document model (TextPointer) and visual representation (coordinates).
public interface ITextView
Remarks
Rather than forcing synchronous layout, callers can subscribe to Avalonia.Controls.Documents.Primitives.ITextView.LayoutUpdated to be notified when layout becomes valid.
Methods
| Name | Description |
|---|---|
| GetLineFromPosition | Gets the line containing the specified position. |
| GetNextLine | Gets the next line after the specified line. |
| GetPositionAtLineEnd | Gets the position at the end of the line containing the specified position. |
| GetPositionAtLineStart | Gets the position at the start of the line containing the specified position. |
| GetPositionAtLineX | Returns the text position on line closest to the specified X coordinate. The result is guaranteed to stay on line; it never crosses into a neighbouring line or block, regardless of how far x lies outside the line's horizontal bounds. |
| GetPreviousLine | Gets the previous line before the specified line. |
| GetRectangleFromTextPosition | Gets the bounding rectangle for a character at the specified position. |
| GetTextPositionFromPoint | Gets the text position from a screen point. |
| GetVisibleLineAtOrAfter | Gets the first visible line at or after the specified position. |
GetLineFromPosition Method
Gets the line containing the specified position.
public Avalonia.Controls.Documents.Primitives.ITextLine GetLineFromPosition(Avalonia.Controls.Documents.TextModel.TextPointer position)
Parameters
position Avalonia.Controls.Documents.TextModel.TextPointer
The text position.
Returns
Avalonia.Controls.Documents.Primitives.ITextLine
The line containing the position, or null if the position is not visible.
GetNextLine Method
Gets the next line after the specified line.
public Avalonia.Controls.Documents.Primitives.ITextLine GetNextLine(Avalonia.Controls.Documents.Primitives.ITextLine currentLine)
Parameters
currentLine Avalonia.Controls.Documents.Primitives.ITextLine
The current line.
Returns
Avalonia.Controls.Documents.Primitives.ITextLine
The next line, or null if at the last line.
GetPositionAtLineEnd Method
Gets the position at the end of the line containing the specified position.
public Avalonia.Controls.Documents.TextModel.TextPointer GetPositionAtLineEnd(Avalonia.Controls.Documents.TextModel.TextPointer position)
Parameters
position Avalonia.Controls.Documents.TextModel.TextPointer
The text position.
Returns
Avalonia.Controls.Documents.TextModel.TextPointer
The position at line end, or null if the position is not visible.
GetPositionAtLineStart Method
Gets the position at the start of the line containing the specified position.
public Avalonia.Controls.Documents.TextModel.TextPointer GetPositionAtLineStart(Avalonia.Controls.Documents.TextModel.TextPointer position)
Parameters
position Avalonia.Controls.Documents.TextModel.TextPointer
The text position.
Returns
Avalonia.Controls.Documents.TextModel.TextPointer
The position at line start, or null if the position is not visible.
GetPositionAtLineX Method
Returns the text position on line closest to the
specified X coordinate. The result is guaranteed to stay on
line; it never crosses into a neighbouring line
or block, regardless of how far x lies outside
the line's horizontal bounds.
public Avalonia.Controls.Documents.TextModel.TextPointer GetPositionAtLineX(Avalonia.Controls.Documents.Primitives.ITextLine line, double x)
Parameters
line Avalonia.Controls.Documents.Primitives.ITextLine
The target line.
x double
The desired X coordinate in view space.
Returns
Avalonia.Controls.Documents.TextModel.TextPointer
A node-aware pointer on line, or null
when the line or its containing element cannot be resolved.
Remarks
This is the structure-first primitive used by vertical caret
navigation. It avoids the offset collisions that affect empty
paragraphs and prevents the hit test from leaking into adjacent
blocks when x is near a block boundary.
GetPreviousLine Method
Gets the previous line before the specified line.
public Avalonia.Controls.Documents.Primitives.ITextLine GetPreviousLine(Avalonia.Controls.Documents.Primitives.ITextLine currentLine)
Parameters
currentLine Avalonia.Controls.Documents.Primitives.ITextLine
The current line.
Returns
Avalonia.Controls.Documents.Primitives.ITextLine
The previous line, or null if at the first line.
GetRectangleFromTextPosition Method
Gets the bounding rectangle for a character at the specified position.
public Avalonia.Rect GetRectangleFromTextPosition(Avalonia.Controls.Documents.TextModel.TextPointer position, Avalonia.Controls.Documents.TextModel.LogicalDirection direction)
Parameters
position Avalonia.Controls.Documents.TextModel.TextPointer
The text position.
direction Avalonia.Controls.Documents.TextModel.LogicalDirection
The logical direction for caret placement at element boundaries.
Returns
The bounding rectangle, or a default rect if the position is not visible or layout is invalid.
Remarks
Check Avalonia.Controls.Documents.Primitives.ITextView.IsLayoutValid before calling this method for accurate results.
GetTextPositionFromPoint Method
Gets the text position from a screen point.
public Avalonia.Controls.Documents.TextModel.TextPointer GetTextPositionFromPoint(Avalonia.Point point, bool snapToText)
Parameters
point Avalonia.Point
The point in view coordinates.
snapToText bool
If true, snaps to the nearest text position even if the point is outside text bounds.
Returns
Avalonia.Controls.Documents.TextModel.TextPointer
The text position, or null if no position could be determined.
GetVisibleLineAtOrAfter Method
Gets the first visible line at or after the specified position.
public Avalonia.Controls.Documents.Primitives.ITextLine GetVisibleLineAtOrAfter(Avalonia.Controls.Documents.TextModel.TextPointer position)
Parameters
position Avalonia.Controls.Documents.TextModel.TextPointer
The text position to search from.
Returns
Avalonia.Controls.Documents.Primitives.ITextLine
The first visible line at or after the position, or null if no
visible line exists at or beyond position.
Remarks
In a virtualizing view, Avalonia.Controls.Documents.Primitives.ITextView.GetLineFromPosition(Avalonia.Controls.Documents.TextModel.TextPointer) returns null
when the target block is not realized. This method skips over unrealized
blocks and returns the first line that the view can resolve. Non-virtualizing
implementations may simply delegate to Avalonia.Controls.Documents.Primitives.ITextView.GetLineFromPosition(Avalonia.Controls.Documents.TextModel.TextPointer).
Properties
| Name | Description |
|---|---|
| IsLayoutValid | Gets whether the view layout is valid and coordinate queries will return accurate results. |
| TextDocument | Gets the TextDocument being rendered. |
IsLayoutValid Property
Gets whether the view layout is valid and coordinate queries will return accurate results.
public bool IsLayoutValid { get; set; }
Remarks
This typically returns true when both measure and arrange have completed. Coordinate mapping methods may return stale or default values when this is false.
TextDocument Property
Gets the TextDocument being rendered.
public Avalonia.Controls.Documents.TextModel.TextDocument TextDocument { get; set; }
Events
| Name | Description |
|---|---|
| LayoutUpdated | Event raised when the view layout has been updated and is now valid. |
LayoutUpdated Event
Event raised when the view layout has been updated and is now valid.
public event EventHandler LayoutUpdated
Remarks
Subscribe to this event to be notified when layout completes, rather than forcing synchronous layout. This integrates with Avalonia's deferred layout system.