I have a custom command in the rich text editor which calls this code. It is supposed to insert an <img> tag with a src=path-to-asset.
protected async void InsertAsset()
{
var newAsset = await selectAssetDialogComponent.SelectAsset();
if (newAsset != null)
{
await Task.Delay(500); // necessary
var src = AB.GetSrc(newAsset.LocalAssetPath);
await sfRteObj.ExecuteCommand(CommandName.InsertHTML, $"<img src=\"{src}\"/>");
}
await InvokeAsync(() => StateHasChanged());
}
This works except for the following:
No matter where I place the cursor in the rich text editor, the <img> HTML tag that is inserted is always at the top of the text, before any existing HTML.
The cursor location is "forgotten" after the dialog closes.
Is there a way to "resume" the previous cursor location ?