CKEditor: set cursor/caret positon

后端 未结 2 1935
囚心锁ツ
囚心锁ツ 2021-01-21 00:08

How can I position the caret in CKEditor3.x? I have 2 positions and I want use insertHTML() on both positions.

Pseudo-code:

editor.setCaret(20); // funct         


        
2条回答
  •  忘掉有多难
    2021-01-21 00:39

    To insert text or do something with html in the editor you don't need to get the caret position.

    Treat it as usual html.

    P.S. If you probably want to restore cursor position after dom manipulating, try this

    var s = editor.getSelection();
    var selected_ranges = s.getRanges(); // save selected range
    // do something
    s.selectRanges(selected_ranges); // restore it
    

提交回复
热议问题