我正在尝试对其进行编码,以便在ckeditor之外单击以将文本插入编辑器。我在下面使用。

if (editorInstance) {
    editorInstance.model.change(writer => {
        writer.insertText(
            ` ${$(this).find('td:last').text()} `,
            editorInstance.model.document.selection.getLastPosition(),
            'end'
        );
    });
}

const text = $('.ck-content').text();
$('.ck-content').val('').focus().text(text);


如果我先输入编辑器,然后单击以插入,一切都很好。如果我只是单击,则插入符号的位置不会转到文本的末尾。是否有简单的解决方案将文本光标移动到ckeditor5的文本末尾?

最佳答案

我自己找到了解决方案,如下所示。

editorInstance.setData('TEXT TO SET');
editorInstance.model.change( writer => {
    writer.setSelection( writer.createPositionAt( editorInstance.model.document.getRoot(), 'end' ));
});


重要的是,首先设置文本,然后再移动插入符号。
我希望这将对将来遇到相同问题的任何人有所帮助。

10-05 20:59
查看更多