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

How to get/set caret position?

1 Answer 148 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Olexandr
Top achievements
Rank 1
Olexandr asked on 04 Feb 2011, 11:41 AM
Hello.

To develop some features in our application we need to get and set caret position (i.e. distance from the beginning of the text or smth like that). It was mentioned by Telerik team in this four-years-old thread that RadEditor did not provide API to get/set caret position.

The only thing we actually need to do is to restore the caret position in design mode after some parts of content are changed (i.e., global reformatting of some keywords). So we store caret position, then some chunks are replaced, then updated HTML is set, and then we set restore caret position.

We have managed to do that in IE using TextRange (such a hack), but it is a really time consuming challenge to get this work properly in all other major browsers.

Browser compatibility is the reason why we use Telerik components. So I hope something have moved further in this area during these four years.

Regards,
Olexandr Vynnychenko
IntraNote a/s

1 Answer, 1 is accepted

Sort by
0
Dobromir
Telerik team
answered on 09 Feb 2011, 01:33 PM
Hi Olexandr,

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


Best wishes,
Dobromir
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Editor
Asked by
Olexandr
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
Share this question
or