get and set cursor at specific position

7 posts, 0 answers
  1. Christian Ungerboeck
    Christian Ungerboeck avatar
    2 posts
    Member since:
    Jul 2005

    Posted 12 Sep 2008 Link to this post

    Hello,

    I want to recieve the position of the cursor in the editor Text and store it in a field (the position is enough for me, there is no need to recover later the selection if there is one). Later if I have finshed with some actions I want to set the cursor back to the same position. I can not use the usual restorepoint handling of the editor because I change the content of the editor in some actions and this destroys the restorepoint in some cases.

    thx for your help 

    Tom (csd)

  2. Rumen
    Admin
    Rumen avatar
    12849 posts

    Posted 15 Sep 2008 Link to this post

    Hi Christian,

    You can get the current caret position by using browser-specific methods. In fact the editor can assist you nicely here, because you can use another of its cross-browser methods:
    var range  = editor.getSelection().getRange();

    This range object is specific for each browser, and its API will differ greatly, so from this point on you will need to write browser-specific code.

    You can also see the following articles
    which provide useful information about caret position, moving and locating the carer position:
    Mouse Cursor Position
    How to set/get caret position of a textfield in IE?
    Working with the Cursor Position.

    To obtain a reference to the editor document use editor.get_document().



    Best regards,
    Rumen
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jeff
    Jeff avatar
    51 posts
    Member since:
    Aug 2007

    Posted 26 Apr 2009 Link to this post

    Hi Rumen,

    I'm having trouble with the Firefox code seen in the "Working with Cursor Position" link. Where do I find the RadEditor element with the selectionStart variable and setSelectionRange() function?

    editor.get_document() doesn't seem to be it.

    Thanks,
    Jeff
  5. Rumen
    Admin
    Rumen avatar
    12849 posts

    Posted 27 Apr 2009 Link to this post

    Hi Jeff,

    The selectionStart property only exists for elements such as input/textbox or textarea. It is no good for using it in an IFRAME - instead the TextRange object and its API should be used in that case.

    These articles could be helpful too:
    http://msdn.microsoft.com/en-us/library/ms533042(VS.85).aspx
    and
    http://www.webreference.com/js/column12/trmethods.html

    Regards,
    Rumen
    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.
  6. Jeff
    Jeff avatar
    51 posts
    Member since:
    Aug 2007

    Posted 27 Apr 2009 Link to this post

    Hi Rumen,

    Thanks for the suggestions, however, I'm looking for cursor control in Firefox. TextRange is strictly IE.

    What can you offer in the way of finding the Editor's cursor position and moving it to a new point in Firefox?

    Thanks,
    Jeff
  7. Tervel
    Admin
    Tervel avatar
    1337 posts

    Posted 28 Apr 2009 Link to this post

    Hi Jeff,

    TextRange object is not specific for IE. It exists in all browsers, but in non-IE browsers its API is completely different. Here are a couple of useful links related to FF for you to explore:

    https://developer.mozilla.org/En/DOM:range#Properties
    http://www.dotvoid.com/2001/03/using-the-range-object-in-mozilla/

    Best wishes,
    Tervel
    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.
  8. Jeff
    Jeff avatar
    51 posts
    Member since:
    Aug 2007

    Posted 28 Apr 2009 Link to this post

    Got it.

    It's the range object for FF, though you can't use document.createRange() to get the editor selection since the editor content is in an IFrame. Instead, you should use editor.getSelection().getRange(); to get a range object (as demonstrated in the second post of this thread).

    With that cleared up, none of this really addresses the problem I'm trying to solve. Therefore, I'm going to start a new thread with the problem stated upfront...
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017