Rich Text Editor forgets cursor location when a dialog is used in a Custom Tool

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 ? 
 

2 Replies

JT Joseph Tan October 31, 2020 07:17 AM UTC

Hey, I found the solution:

            await sfRteObj.SaveSelection();

            await sfRteObj.RestoreSelection();




IS Indrajith Srinivasan Syncfusion Team November 2, 2020 08:28 AM UTC

Hi Joseph,

We are glad that you got an solution for the reporetd query,

Please get back to us if you need any further assistance.

Regards,
Indrajith

Loader.
Up arrow icon