Skip to main content

ITextView Interface

Definition​

Assembly:Avalonia.Controls.Documents
Package:Avalonia.Controls.Documents

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​

NameDescription
GetLineFromPositionGets the line containing the specified position.
GetNextLineGets the next line after the specified line.
GetPositionAtLineEndGets the position at the end of the line containing the specified position.
GetPositionAtLineStartGets the position at the start of the line containing the specified position.
GetPositionAtLineXReturns 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.
GetPreviousLineGets the previous line before the specified line.
GetRectangleFromTextPositionGets the bounding rectangle for a character at the specified position.
GetTextPositionFromPointGets the text position from a screen point.
GetVisibleLineAtOrAfterGets 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​

Avalonia.Rect

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​

NameDescription
IsLayoutValidGets whether the view layout is valid and coordinate queries will return accurate results.
TextDocumentGets 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​

NameDescription
LayoutUpdatedEvent 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.