如何在tinyMCE中设置插入符的位置?

问题描述 投票:0回答:1

我在Vue组件中创建基于TinyMCE的自定义编辑器。@input插入符号位置设置为0后(到左侧位置)

所以我获得插入位置

window.tinyMCE.activeEditor.selection.getRng().startOffset

但是我无法设置

window.tinyMCE.activeEditor.selection.setRng(4)
window.tinyMCE.activeEditor.setContent('<p>test test</p>')

也无法使用

var ed = window.tinyMCE.activeEditor.selection
ed.setCursorLocation(ed.getContent(), 3)

请帮助

vue.js tinymce vue-component tinymce-4
1个回答
0
投票

在我的编辑器中,我使用了这个:

let rng = tinymce.DOM.createRng(); // the range object
var newNode = editor.dom.select('#_mce_temp_rob')[0];
rng.setStart(newNode.firstChild, 0); // 0 is the offset, it will be at the beginning of the line.
rng.setEnd(newNode.firstChild, 0);
editor.selection.setRng(rng);

现在,我猜想具体实现会因您的情况而有所不同,因为我刚回来时就做过,虽然记不清了很多,但希望对您有所帮助。更多详情:https://exceptionshub.com/whats-the-best-way-to-set-cursorcaret-position.html

© www.soinside.com 2019 - 2024. All rights reserved.