Selection service

    Inspect, select or clear the current text range. Read selected text separately from selected HTML when your application needs literal values.

    The facade is available as editor.Selection; its interface can be replaced by an application implementation.

    Actual Avalonia editor showing the document and native authoring controls.
    Actual Avalonia editor showing the document and native authoring controls.

    Use it in your application

    Indices are UTF-16 units in the active view. Keep a selection and its document ownership together across awaited work instead of reusing a stale range.

    All examples assume an editor named editor, already attached to a visible window, and an awaited editor.Ready. Keep operations asynchronous instead of blocking the UI thread.

    string text = await editor.Selection.GetSelectedTextAsync();
    string selectedHtml = await editor.Selection.GetSelectedHtmlAsync();

    Members

    These signatures come from the delivered 1.0.2 assemblies and XML documentation. Cancellation tokens can be supplied to awaited operations. Follow the source-specific notes above when adapting a WPF integration.

    MemberSignature
    DeselectAllAsyncTask DeselectAllAsync(CancellationToken cancellationToken)
    GetSelectedHtmlAsyncTask<string> GetSelectedHtmlAsync(CancellationToken cancellationToken)
    GetSelectedTextAsyncTask<string> GetSelectedTextAsync(CancellationToken cancellationToken)
    GetSelectionInfoAsyncTask<SelectionInfo> GetSelectionInfoAsync(CancellationToken cancellationToken)
    GetSelectionLengthAsyncTask<int> GetSelectionLengthAsync(CancellationToken cancellationToken)
    SelectAllAsyncTask SelectAllAsync(CancellationToken cancellationToken)
    SelectTextAsyncTask SelectTextAsync(int startIndex, int length, CancellationToken cancellationToken)
    SelectTextAsyncTask SelectTextAsync(int startIndex, CancellationToken cancellationToken)
    TrimSelectionAsyncTask<string> TrimSelectionAsync(TrimDirections trimDirection, CancellationToken cancellationToken)
    UnselectAsyncTask UnselectAsync(CancellationToken cancellationToken)

    Continue with

    Last updated on Oct 18, 2026

    Put this into practice.

    Start with the C# Avalonia sample. Restore this edition's package and install the native browser prerequisites before running it.

    Prefer a guided look? Book a free live demo with our engineers - live on Zoom or Teams, never a chatbot.