Caret service

    Read and position the caret in the current editing view. Use it to place inserted content or restore a visible authoring position.

    The facade is available as editor.Caret; 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

    Text indices are UTF-16 units in the API-defined current view. They are not positions in an encoded HTML file or interchangeable with legacy MSHTML ranges.

    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.

    await editor.Caret.SetCaretAtEndAsync();
    int index = await editor.Caret.GetCaretIndexAsync();

    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
    GetCaretBoundsAsyncTask<Nullable<Rect>> GetCaretBoundsAsync(CancellationToken cancellationToken)
    GetCaretIndexAsyncTask<int> GetCaretIndexAsync(CancellationToken cancellationToken)
    GetCaretIndexInHtmlAsyncTask<int> GetCaretIndexInHtmlAsync(CancellationToken cancellationToken)
    GetCaretPositionAsyncTask<Nullable<Point>> GetCaretPositionAsync(CancellationToken cancellationToken)
    HideAsyncTask HideAsync(CancellationToken cancellationToken)
    ScrollToCaretViewAsyncTask ScrollToCaretViewAsync(CancellationToken cancellationToken)
    SetCaretAtAsyncTask SetCaretAtAsync(double x, double y, bool scrollToView, CancellationToken cancellationToken)
    SetCaretAtEndAsyncTask SetCaretAtEndAsync(CancellationToken cancellationToken)
    SetCaretAtHomeAsyncTask SetCaretAtHomeAsync(CancellationToken cancellationToken)
    SetCaretAtLineBeginningAsyncTask SetCaretAtLineBeginningAsync(CancellationToken cancellationToken)
    SetCaretAtLineEndAsyncTask SetCaretAtLineEndAsync(CancellationToken cancellationToken)
    SetCaretByIndexAsyncTask SetCaretByIndexAsync(int index, CancellationToken cancellationToken)
    SetCaretByIndexAsyncTask SetCaretByIndexAsync(int index, int length, CancellationToken cancellationToken)
    SetCaretPositionAsyncTask SetCaretPositionAsync(double x, double y, bool scrollToView, CancellationToken cancellationToken)
    ShowAsyncTask ShowAsync(bool scrollToView, 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.