HTMLEditor SaveSelection and RestoreSelection not reflecting

Hi,
I am facing an issue while try to "SaveSelection" and "RestoreSelection"
Demo also not saving and restoring cursor location before adding date value.

Here is the edited code below:

<RadzenHtmlEditor  @ref="HtmlEditor" style="height: 200px;" Execute=@OnExecute  Change=@OnChange>
    <RadzenHtmlEditorCustomTool CommandName="InsertToday" Icon="today" Title="Insert today" />
</RadzenHtmlEditor>

@code {

    public RadzenHtmlEditor HtmlEditor { get; set; }
    async Task OnExecute(HtmlEditorExecuteEventArgs args)
    {
        await HtmlEditor.RestoreSelectionAsync();
        StateHasChanged();
        if (args.CommandName == "InsertToday")
        {
            await InsertDate(args.Editor, DateTime.Now);
        }
    }

    async Task InsertDate(RadzenHtmlEditor editor, DateTime date)
    {
        await editor.ExecuteCommandAsync(HtmlEditorCommands.InsertHtml, $"<strong>{date.ToLongDateString()}</strong>");
    }
    
     async Task OnChange()
{
    await HtmlEditor.SaveSelectionAsync();
}
}

The Change event is fired after the editor loses focus. This also means it has lost the selection too. This is why saving selection in the OnChange method has no effect.

Hi,

Thanks for the speedy reply.

Is there a way to preserve the selection when the editor loses focus?

You can try handling the Input event instead of Change and see if it helps.