Skip to content
Advertisement

How to move the cursor position within SCeditor?

I am inserting text into an instance of SCeditor and would like to move the cursor after the insert, to a specific position within the inserted text.

Code of the SCeditor init:

JavaScript

How to move the cursor?


Related Code I have found deals with the range object, but there was no example of how to move the cursor:

JavaScript

Advertisement

Answer

Messing around with ranges is fairly horrible. The easiest way is probably to insert the text as HTML and include some special selection markers that SCEditor uses to restore selections. This should work:

JavaScript

When in source mode, it much easier (doesn’t work in WYSIWYG mode, might be something it should do):

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement