Completed
Last Updated: 04 Sep 2019 15:44 by ADMIN
ADMIN
Ianko
Created on: 10 Oct 2013 14:54
Category: Editor
Type: Bug Report
1
Fix when a table is inserted under IE , the cursor cannot be set outside of the table
Inserting a table is causing the user to switch to HTML mode and insert manually a br element, so that he could start typing in the next line.

Possible solution is attaching this Client-side method on the OnClientCommandExecuted event of the RadEditor control:

<telerik:RadEditor runat="server" ID="RadEditor1"
    OnClientCommandExecuted="OnClientCommandExecuted"></telerik:RadEditor>


<script type="text/javascript">
    function OnClientCommandExecuted(editor, args) {
        var command = args.get_commandName();
        if (command = "InsertTable") {
            var selection = editor.getSelection();
            var range = selection.getRange();
            if (range.pasteHTML) {
                range.pasteHTML("<br />");
            }
            else {
                editor.pasteHtml("<br/>");
            }
        }
    }
</script>

The following workaround entirely changes the behavior by modifying the selection and selects the first TD

<telerik:RadEditor runat="server" ID="RadEditor1" OnClientPasteHtml="OnClientPasteHtml">
</telerik:RadEditor>

<script type="text/javascript">
    var identifierID = "RadEditor_AfterTable";

    function OnClientPasteHtml(editor, args) {
        var commandName = args.get_commandName();

        if (commandName === "InsertTable" || commandName === "TableWizard" ) {
            var currValue = args.get_value();
            currValue = currValue.replace(/<\/table>/gi, "</table><div id=" + identifierID + ">&#x200B;</div>");
            //currValue = currValue + "<div id=" + identifierID + ">&#x200B;</div>";
            
            args.set_value(currValue);
            setTimeout(function () {
                selectFirstTD(editor)
            }, 0);
        }
    }

    function selectFirstTD(editor) {
        var $ = $telerik.$;
        var contBody = editor.get_contentArea();
        var identifier = $(contBody).find("#" + identifierID);
        var table = identifier.prev();
        var elmToSelect = table.find("th")[0] || table.find("td")[0];

        if (elmToSelect.childNodes && !$telerik.isIE) {
            elmToSelect = elmToSelect.childNodes[0].nodeName === "#text" && elmToSelect.childNodes[0];
        }

        var hasNextElement = identifier.next()[0];
        
        while (hasNextElement && $(hasNextElement).is("style")) {
            hasNextElement = $(hasNextElement).next()[0];
        }
        
        editor.selectElement(elmToSelect);

        if (!hasNextElement) {
            table.after("<br/>");
        }

        identifier.remove();
    }
</script>
0 comments