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

How to move caret to end of editor

3 Answers 534 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Joey
Top achievements
Rank 1
Joey asked on 11 Jul 2016, 11:34 PM
How do we move the cursor position to the end of the editor after changing its HTML content? Sometimes after setting editor.value("some new html string") I get the cursor position reset to the start of the text in the editor box, I'll like to have it at the end of the text in the editor box so that the user can continue typing, I can't seem to find any example in the demos, can someone guide me on this? Thank you.

3 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 12 Jul 2016, 08:30 AM
Hi,

Here is a sample dojo which shows changing editor's content and moving the cursor at the end of the content area (http://dojo.telerik.com/ApIFO/3).

You can also review the following articles about using range object:
Regards,
Nikolay
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
0
Joey
Top achievements
Rank 1
answered on 13 Jul 2016, 04:18 PM

Hi Nikolay, thanks for the dojo sample. It works in IE and Chrome, but there seems to be a bug in firefox. Pressing space before moving the cursor seems to add an unintended line break each time.

Please see the following screen cast:

http://screencast.com/t/q70wk0wY7Z

 

0
Nikolay
Telerik team
answered on 14 Jul 2016, 08:47 AM
Hi,

Firefox adds a line break when space key has pressed (http://screencast.com/t/mexAfzImIVHU) and editor.value() returns the HTML along with the BR. The editor does not have custom logic for space key and leave it to the browser.

To resolve the issue, you can strip the line break before changing the editor content using regular expression. Another approach is to handle keydown/up events and remove the BR if it is not added by the user or implement adding of a space on keydown and cancel the event.

You can review the editor methods and events here (http://docs.telerik.com/kendo-ui/api/javascript/ui/editor).

Regards,
Nikolay
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
Tags
Editor
Asked by
Joey
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Joey
Top achievements
Rank 1
Share this question
or