【发布时间】:2019-12-09 14:06:57
【问题描述】:
在下面的代码中,编辑器在按下按钮时插入了一些文本,然后编辑器聚焦光标。但是,它将光标聚焦在文本区域的开头。我希望它集中在放置在那里的文本之后。这怎么可能?虽然我查看了 API 并使用了 writer、setSelection 等,但我根本不理解它们,也未能正确使用它们,因此感谢您提供任何帮助。
<div id="editor">
<p>Editor content goes here.</p>
</div>
<br>
<button id="focusSet">Focus</button>
<script>
// Editor configuration.
ClassicEditor
.create( document.querySelector( '#editor' ))
.then( editor => {
window.editor = editor;
})
.catch( error => {
console.error( error );
});
document.getElementById('focusSet').onclick = function(e) {
window.editor.setData('text');
window.editor.editing.view.focus();
};
</script>```
How would I change this code to set the cursor to the end of the text? This comes from a jsfiddle
[JsFiddle][1]
[1]: https://jsfiddle.net/30mb2ef9/2/
【问题讨论】: