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

Expand selection from current cursor position

3 Answers 70 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 02 Feb 2014, 11:39 PM
In the RadEditor, if I have  a text selection which spans partial words, how can I programatically expand it that so that the selection includes only full words?

Example (Square brackets represent the selection).

Start with this:   THIS IS MY SENTEN[CE IN THE RAD]EDITIOR

Change to this: THIS IS MY [SENTENCE IN THE RADEDITIOR]

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Feb 2014, 10:07 AM
Hi Martin,

Please have a look into the sample code snippet which works fine at my end.

ASPX:
<telerik:RadEditor ID="RadEditor1" runat="server">
</telerik:RadEditor>
<telerik:RadButton ID="RadButton1" runat="server" Text="Expand Selection" AutoPostBack="false"
    OnClientClicked="OnClientClicked1">
</telerik:RadButton>

JavaScript:
<script type="text/javascript">
    function OnClientClicked1(sender, args) {
        var editor = $find("<%=RadEditor1.ClientID %>");
        var s = editor.get_contentArea().textContent;
        var first = s.split("[");
        var second = first[1].split("]");
        var originalword = "";
        firstwords = first[0].split(" ");
        secondwords = second[0].split(" ");
        for (var i = 0; i < (firstwords.length) - 1; i++) {
            originalword += firstwords[i];
            originalword += " ";
        }
        originalword += "[";
        originalword += firstwords[i];
        originalword += secondwords[0];
        for (var i = 1; i < secondwords.length; i++) {
            originalword += " ";
            originalword += secondwords[i];
        }
        originalword += second[second.length - 1];
        originalword += "]";
        editor.get_contentArea().textContent = originalword;
    }
</script>

Thanks,
Princy.
0
Martin
Top achievements
Rank 1
answered on 03 Feb 2014, 11:12 AM
Hi Princy.

Thanks for your reply, although I don't think I was clear in my question.

The square brackets in my post were only there to illustrate the start and end points of a user's text selection. They wouldn't actually be present in the content.
0
Princy
Top achievements
Rank 2
answered on 04 Feb 2014, 03:42 AM
Hi Martin,

With reference to this forum thread RadEditorSelection Client side API Offers getRange() and SelectRange() methods to get/restore the cursor position. You need to get a reference to the RadEditor Document with editor.get_document(); and create a range. After creating a text range  you will be able to use the methods like move(),moveStart(),moveEnd() and select().

Thanks,
Princy.
Tags
Editor
Asked by
Martin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Martin
Top achievements
Rank 1
Share this question
or