Skip to main content

ITextEditorHost Interface

Definition​

Assembly:Avalonia.Controls.RichTextEditor
Package:Avalonia.Controls.RichTextEditor

Host interface for text editor controls that support text mutation.

public interface ITextEditorHost

Remarks​

Extends Avalonia.Controls.Documents.Primitives.IInteractiveTextHost with editing-specific members: read-only gating, return/tab acceptance. Components that perform text mutation (typing, delete, paste, undo) require this interface.

Read-only interactive views should implement Avalonia.Controls.Documents.Primitives.IInteractiveTextHost directly instead.

Methods​

NameDescription
RedoRedoes the most recently undone editing operation and restores any caret/selection state captured with the undo unit.
UndoUndoes the most recent editing operation and restores any caret/selection state captured with the undo unit.

Redo Method​

Redoes the most recently undone editing operation and restores any caret/selection state captured with the undo unit.

public void Redo()

Remarks​

All callers should route through this method instead of calling Avalonia.Controls.Documents.Undo.UndoManager.Redo directly, for the same reason Avalonia.Controls.Documents.Primitives.ITextEditorHost.Undo gives.

Undo Method​

Undoes the most recent editing operation and restores any caret/selection state captured with the undo unit.

public void Undo()

Remarks​

All callers (keyboard shortcuts, editor actions, menu items) should route through this method instead of calling Avalonia.Controls.Documents.Undo.UndoManager.Undo directly - direct calls skip caret restoration, which is what an implementation that only forwards to the undo manager produces.

Properties​

NameDescription
AcceptsReturnGets whether the editor accepts the Return/Enter key.
AcceptsTabGets whether the editor accepts the Tab key.
IsReadOnlyGets whether the editor is in read-only mode.
SelectionFlyoutGets the selection mini-bar flyout shown when text is selected.
ShowSelectionFlyoutGets whether the selection mini-bar flyout is enabled.

AcceptsReturn Property​

Gets whether the editor accepts the Return/Enter key.

public bool AcceptsReturn { get; set; }

Remarks​

When true, pressing Enter inserts a line break or paragraph. When false, Enter may trigger a command or be ignored.

AcceptsTab Property​

Gets whether the editor accepts the Tab key.

public bool AcceptsTab { get; set; }

Remarks​

When true, pressing Tab inserts a tab character. When false, Tab moves focus to the next control.

IsReadOnly Property​

Gets whether the editor is in read-only mode.

public bool IsReadOnly { get; set; }

Remarks​

When true, editing operations are disabled but navigation and selection still work.

SelectionFlyout Property​

Gets the selection mini-bar flyout shown when text is selected.

public Avalonia.Controls.Documents.Primitives.EditorSelectionFlyout SelectionFlyout { get; set; }

Remarks​

The mini-bar is chrome a control chooses to show, not an editing capability, so a host that presents no flyout leaves this null.

ShowSelectionFlyout Property​

Gets whether the selection mini-bar flyout is enabled.

public bool ShowSelectionFlyout { get; set; }

Events​

IsReadOnlyChanged Event​

Occurs when the Avalonia.Controls.Documents.Primitives.ITextEditorHost.IsReadOnly state changes.

public event EventHandler IsReadOnlyChanged

Remarks​

Toolbar tools and editor actions subscribe to this event to refresh their enabled state when read-only mode is toggled at runtime. A host that never toggles Avalonia.Controls.Documents.Primitives.ITextEditorHost.IsReadOnly can declare the event and never raise it; what it must not do is accept a subscription and drop it, which leaves the whole toolbar permanently stale with nothing to diagnose.