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

get and set cursor at specific position

6 Answers 894 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Christian Ungerboeck
Top achievements
Rank 1
Christian Ungerboeck asked on 12 Sep 2008, 12:26 PM

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)

6 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 15 Sep 2008, 07:30 AM
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.
0
Jeff
Top achievements
Rank 1
answered on 27 Apr 2009, 12:37 AM
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
0
Rumen
Telerik team
answered on 27 Apr 2009, 12:39 PM
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.
0
Jeff
Top achievements
Rank 1
answered on 27 Apr 2009, 06:20 PM
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
0
Tervel
Telerik team
answered on 28 Apr 2009, 07:38 AM
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.
0
Jeff
Top achievements
Rank 1
answered on 29 Apr 2009, 12:46 AM
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...
Tags
Editor
Asked by
Christian Ungerboeck
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Jeff
Top achievements
Rank 1
Tervel
Telerik team
Share this question
or