Opening custom dialog in RadEditor; not keeping focus when opening, after Chrome vers.125 update

1 Answer 48 Views
General Discussions
Christopher
Top achievements
Rank 1
Christopher asked on 21 May 2024, 02:46 AM

Hello Telerik crew,

After the recent Chrome update (vers 125.0.6422.61), I am encountering strange behavior when opening a custom dialog from within a RadEditor control. I have not experienced the below issue in Firefox nor Edge, only latest version of Chrome.

If plain text is selected (i.e.: no html formatting), the custom dialog is launched and the text loses it's focus which in-turn causes a hyperlink to be pasted directly after the text I had selected. If an A tag is selected, the custom dialog is launched and the selected A tag doesn't lose focus.

I have included the code I am using to launch the custom dialog:

            Telerik.Web.UI.Editor.CommandList["InsertHyperlink_FWText"] = function (commandName, editor, args) {
                // only continue if we have actual text selected in <textarea>
                var selected_text = editor.getSelection().getText();
                if (selected_text != "" || editor.getSelectedElement().tagName == "A") {
                    var elem = editor.getSelectedElement(); //returns the selected element.
                    var flag = true;
                    var parent_elem = elem.parentElement;
                    if (elem.tagName == "A") {
                        if (elem.getAttribute('class') == "advbutton") {
                            flag = false;
                        }
                        editor.selectElement(elem);
                        argument = elem;
                    } else {
                        do { //set up the parent element and find the encapsulating A tag
                            parent_elem = parent_elem.parentElement;
                            if (parent_elem == null) { break; }
                        } while (parent_elem.tagName != "A");
                    
                        if (parent_elem != null) {
                            if (parent_elem.tagName == "A") {
                                if (parent_elem.getAttribute('class') == "advbutton") {
                                    flag = false;
                                }
                                selected_text = parent_elem.innerHTML;
                                editor.selectElement(parent_elem);
                                argument = parent_elem;
                            }
                        } else {
                            //remove links if present from the current selection - because of JS error thrown in IE
                            editor.fire("Unlink");
                            //remove Unlink command from the undo/redo list
                            var commandsManager = editor.get_commandsManager();
                            var commandIndex = commandsManager.getCommandsToUndo().length - 1;
                            commandsManager.removeCommandAt(commandIndex);
                            //
                            var content = editor.getSelectionHtml();
                            var link = editor.get_document().createElement("A");
                            link.innerHTML = content;
                            argument = link;
                        }
                    }

                    // only if dealing with a hyperlink advanced button, do we continue
                    if (flag == true) {
                        //---------------- Classic ASP Hyperlink Editor ---------------------------------------------
                        var doChooseLink = function (elem) {
                            var objEl = new Object();
                            if (elem.getAttribute("href") != null) {
                                objEl.href = elem.getAttribute("href");
                                objEl.target = elem.getAttribute("target");
                                objEl.title = elem.getAttribute("title");
                            } else {
                                objEl.href = ""
                                objEl.target = ""
                                objEl.title = ""
                            }
                            var args = new Array();
                            args["objEl"] = objEl;
                            args["Mode"] = "doclink"
                            flexDialog(620, 410, "/fw/_theditor/ed_links.asp", args, doChooseLink_CallBack, null);
                        }

                        var doChooseLink_CallBack = function (retValue, objEl) {
                            if (retValue.href == "") {
                                editor.pasteHtml(String.format(selected_text));
                            } else {
                                if (selected_text.charAt(selected_text.length - 1) == ' ') {
                                    selected_text = selected_text.substring(0, selected_text.length - 1);
                                    editor.pasteHtml(String.format("<a href='{0}' title='{1}' target='{2}'>" + selected_text + "</a> ", retValue.href, retValue.title, retValue.target));
                                } else {
                                    editor.pasteHtml(String.format("<a href='{0}' title='{1}' target='{2}'>" + selected_text + "</a>", retValue.href, retValue.title, retValue.target));
                                }
                            }
                        }

                        doChooseLink(argument);
                        //---------------- END Classic ASP Hyperlink Editor ---------------------------------------------
                    }
                }
            };

Please let me know if you need any other information, or a clearer explanation of the issue I am experiencing in Chrome (vers.125) only).

Thank you!

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 21 May 2024, 11:43 AM

Hi Christopher,

Your screenshots and code indicate that you are using a custom flexDialog dialog instead of the built-in custom dialogs of RadEditor. The built-in dialogs are designed to handle text selection and restoration correctly.

I tested the built-in Insert Link, Hyperlink, and the Custom InsertSpecialLink dialog of RadEditor. All of them correctly link the text selection in the latest Chrome Version 125.0.6422.61.

I recommend modifying your solution to use a custom RadEditor dialog. The custom dialogs internally manage (store and restore) the selection, providing better support for Chrome.

Best Regards,
Rumen
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
Tags
General Discussions
Asked by
Christopher
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or