This is a migrated thread and some comments may be shown as answers.

[Solved] Replace adds extra text

1 Answer 235 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Jeremy
Top achievements
Rank 1
Jeremy asked on 08 May 2009, 12:55 AM
If you're in IE (possibly other browsers too?) and the html starts with a tag, doing a replace will add the replace to the top.

Eg: change nott to not as below

Before replace:

<strong>Bold</strong>
nott bold

After replace:

<strong>not Bold</strong>
not bold

Fix: in FindAndReplace.ascx

_replace: function(search_str, str) {
        var newStr = str;
        //escape html content (find and replace is not supposed to work in HTML view anyway).
        if (newStr)
            newStr = newStr.replace(/&/gi, "&amp;").replace(/</gi, "&lt;").replace(/>/gi, "&gt;");
        if (this.getSelection().getHtml()) {
            if ($telerik.isIE) {
                //IE selection bug
                try {
                    this.getSelection().getRange().duplicate().pasteHTML(newStr);
                }
                catch (uspecifiedError) {
                    //unspecified error is thrown when replacing text inside a textarea element
                    this.getSelection().getRange().text = newStr;
                }
            }
            else {
                this._clientParameters._editor.pasteHtml(newStr, "FindAndReplace");
            }
        }
    },

needs to be changed to (after adding a reference to JQuery):

_replace: function(search_str, str) {
        var newStr = str;
        //escape html content (find and replace is not supposed to work in HTML view anyway).
        if (newStr)
            newStr = newStr.replace(/&/gi, "&amp;").replace(/</gi, "&lt;").replace(/>/gi, "&gt;");
        var html = this.getSelection().getHtml();
        if (html && $('<span>' + html + '</span>')[0].innerText) {

            if ($telerik.isIE) {
                //IE selection bug
                try {
                    this.getSelection().getRange().duplicate().pasteHTML(newStr);
                }
                catch (uspecifiedError) {
                    //unspecified error is thrown when replacing text inside a textarea element
                    this.getSelection().getRange().text = newStr;
                }
            }
            else {
                this._clientParameters._editor.pasteHtml(newStr, "FindAndReplace");
            }
        }
    },

1 Answer, 1 is accepted

Sort by
0
Lini
Telerik team
answered on 11 May 2009, 10:10 AM
Hello,

Thank you for the provided information. We will fix the problem for the next service pack release of the RadControls for ASP.NET AJAX suite. The fix will is very simple:

if (this.getSelection().getHtml()) {
...

becomes:

        var selectionText = this.getSelection().getText();
        if (selectionText) {
...


Best wishes,
Lini
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Editor
Asked by
Jeremy
Top achievements
Rank 1
Answers by
Lini
Telerik team
Share this question
or