Completed
Last Updated: 10 Aug 2021 13:31 by ADMIN
Release Q2 2015
ADMIN
Ianko
Created on: 04 Sep 2014 05:29
Category: Editor
Type: Bug Report
1
FindAndReplace dialog's logic breaks when   entities present in a text node under IE
Having the entity in a sentence, and trying to find or find and replace in this sentence, the found word seem to be incorrectly highlighted/selected. Therefore, when trying to replace, incorrect selection is replaced.

A possible fix is adding the entities inside span elements, so that additional inner text nodes are created.

The following code example implements such functionality upon opening and closing the FindAndReplace dialog 
<telerik:RadEditor ID="RadEditor1" runat="server" OnClientCommandExecuted="OnClientCommandExecuted">
    <Content>
        <p>some text.&nbsp; some text.</p>
    </Content>
</telerik:RadEditor>

<script type="text/javascript">
    function OnClientCommandExecuted(editor, args) {
        var commandName = args.get_commandName();

        if ($telerik.isIE && commandName === "FindAndReplace") {
            updateNbspEntities(editor, true);

            var dialog = editor.get_dialogOpener()._dialogContainers[commandName];
            dialog.add_close(function () {
                updateNbspEntities(editor, false);

            });
        }
    };

    function updateNbspEntities(editor, toAddInNodes) {
        var html = editor.get_html(true);

        if (toAddInNodes) {
            // insert all &nbsp; entities inside nodes to fix IE ranges
            html = html.replace(/((&nbsp;)+)/gi, "<span>$1</span>");
        } else {
            // restore them when FindAndReplace dialog is closed
            html = html.replace(/<span>((&nbsp;)+)<\/span>|<font>((&nbsp;)+)<\/font>/gi, "$1");
        }

        editor.set_html(html);
    };
</script>
0 comments