RadEditor - How to Get cursor position

7 posts, 0 answers
  1. nickybeit
    nickybeit avatar
    7 posts
    Member since:
    Jun 2011

    Posted 15 Jun 2011 Link to this post

    Hi Support,

    I've an application using RadEditor control.

    I've a scenario where I've to "set the cursor position" or "set text selection range" in javascript.

    How can achieve this functionality? Are there any methods provided for this functionality?

    Awaiting sooner reply


    Regards
    Nickybeit
  2. nickybeit
    nickybeit avatar
    7 posts
    Member since:
    Jun 2011

    Posted 15 Jun 2011 Link to this post

    i'm still waiting for the response.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rumen
    Admin
    Rumen avatar
    12846 posts

    Posted 17 Jun 2011 Link to this post

    Hello Nickybeit,

    RadEditorSelection's client-side API offers getRange() and selectRange() methods to get / restore cursor position.

    RadEditorSelection utilizes W3C Range and Microsoft TextRange objects to provide cross-browser support, however, for more advanced manipulations you will need to use the standard objects. More detailed information regarding W3C Range and Microsoft TextRange is available in the following articles:

    http://www.wrox.com/WileyCDA/Section/JavaScript-DOM-Ranges-Page-2.id-292302.html
    http://www.quirksmode.org/dom/range_intro.html
    http://msdn.microsoft.com/en-us/library/ms535872%28VS.85%29.aspx

    http://www.quirksmode.org/js/findpos.html


    Greetings,
    Rumen
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  5. Abhinav
    Abhinav avatar
    5 posts
    Member since:
    Feb 2014

    Posted 08 Jun 2015 Link to this post

    Hello,

    How we can get the current cursor index from the radeditor? I need to add some text from the server side in radeditor on the current cursor position.

    I have also tried "editor.getSelection().getRange(true);", but in jquery alert i am not see any index or position. My requirement is to find the current cursor index in client side or server side.

    Please suggest.

  6. Ianko
    Admin
    Ianko avatar
    1535 posts

    Posted 09 Jun 2015 Link to this post

    Hello Abhinav,

    The client-side getRange() methods returns an instance of an Range object, which is created by the browser, and in order to somehow determine the selection ranges, you should use the startOffset and endOffset properties. Although, this is a general knowledge regarding the browser's selection, and you can read more about it in this help articles:

    As for the requirements posted, you cannot manipulate the range/selection via server-side technique. This is a browser functionality, and can be handled only on the client. For example:

    <telerik:RadButton runat="server" ID="RadButton1" Text="Store Range" OnClientClicked="storeRange" AutoPostBack="false"/>
    <telerik:RadButton runat="server" ID="Button1" Text="Insert in stored Range" OnClientClicked="insertInRange" AutoPostBack="false" />
      
    <script type="text/javascript">
        var _storedRange = {};
      
        function storeRange(sender, args) {
            var editor = $find("<%= RadEditor1.ClientID %>");
            var selection = editor.getSelection();
      
            _storedRange = selection.getRange();
        }
      
        function insertInRange(sender, args) {
            var editor = $find("<%= RadEditor1.ClientID %>");
            var selection = editor.getSelection();
      
            selection.selectRange(_storedRange);
            editor.pasteHtml("some text");
        }
    </script>


    Regards,

    Ianko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  7. Abhinav
    Abhinav avatar
    5 posts
    Member since:
    Feb 2014

    Posted 10 Jun 2015 Link to this post

    I have tried startOffset and endOffset properties but it is not giving the correct index. If i put my cursor on the starting of the 4th paragraph in the editor these properties gives 0.

    Also, i need a way though that i can store my cursor index or position in the hidden field or something like that and after postback add some text into the editor with current cursor position(which was in the hidden field).

    Please suggest.

     

  8. Ianko
    Admin
    Ianko avatar
    1535 posts

    Posted 11 Jun 2015 Link to this post

    Hi Abhinav,

    Such complex Range/Selection manipulations can be done only via the browser's Range/Selection object, and RadEditor does not expose any specific API to facilitate its usage in such a scenario. This should be handled by using only the browser's client-side API.

    Regards,
    Ianko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017