Cannot move ckeditor 4 selection to beginning
- by Gary Hillerson
I've been exploring numerous solutions in stackoverflow and elsewhere to try to get ckeditor 4 to scroll to the top after I've programmatically added a number of pages to it, using CKEditor's InsertHtml function. After adding my html, which looks fine, I want to position the cursor at the beginning.
Here's one of a variety of things I've tried without success:
function MoveCaretToStart(myEditor) {
    var range = new CKEDITOR.dom.range( editor.document );
    range.selectNodeContents(editor.document.getBody());
    range.moveToElementEditStart(range.root);  // also tried range.collapse(true);
    range.select();
}
...
MoveCaretToStart(CKEDITOR.instances['myEditor']);  // which already has contents in it
This doesn't throw any errors, but also doesn't move the cursor position (it remains at the end of the doc). I thought this one would be easy, but it sure hasn't been. Any help appreciated.