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

Implements: IInteractiveTextHost, ITextViewHost

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.IUndoManager.Redo directly. The default implementation forwards to the document's undo manager without restoring caret state; editor controls should override to add restoration.

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.IUndoManager.Undo directly — direct calls skip caret restoration. The default implementation forwards to the document's undo manager without restoring caret state; editor controls should override to add restoration.

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; }

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. The default implementation is a no-op, which is acceptable for hosts that never toggle Avalonia.Controls.Documents.Primitives.ITextEditorHost.IsReadOnly.