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:
var textarea = $('textarea[name="'+fieldname+'"]')[0];
// shortcut to insert custom text
sceditor.instance(textarea).addShortcut('ctrl+alt+b', function()
{
var fieldname = this.opts.id;
parent.window['sce_'+fieldname].insertText('\\sqrt{}');
// move cursor one to the left, so it is within the two brackets
// ...
return;
}
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:
var rangeHelper = this.getRangeHelper();
var range = rangeHelper.selectedRange();
rangeHelper.selectRange(range);
range.setStartAfter(parent);
rangeHelper.selectRange(range);