How to set cursor position to end of text in CKEditor?

后端 未结 8 1312
予麋鹿
予麋鹿 2020-12-01 12:34

Is there a way to set the cursor to be at the end of the contents of a CKEditor?

This developer asked too, but received no answers:

http://cksource.com/forum

8条回答
  •  庸人自扰
    2020-12-01 13:21

    CKEditor 3.x:

    on : {
            'instanceReady': function(ev) {
               ev.editor.focus();
               var range = new CKEDITOR.dom.range( ev.editor.document );
               range.collapse(false);
               range.selectNodeContents( ev.editor.document.getBody() );
               range.collapse(false);
               ev.editor.getSelection().selectRanges( [ range ] );
            }
         }
    

    based on pseudo-code provided by the developers here:

    https://dev.ckeditor.com/ticket/9546#comment:3

    You have to focus editor, get document object, put it in range, collapse range (with false parameter), select body (with selectNodeContents), collapse it (with false parameter) and finally select range. It is best to do it all in instanceReady event.

提交回复
热议问题