5

为 TinyMCE 制作一个自定义插件,我想知道如何根据当前光标位置自动选择一个单词,就像在 Wordpress“添加链接”插件中一样。

我已经搜索了 Wordpress TinyMCe Wplink 代码和 TinyMCE Docs,但我没有参考......

4

1 回答 1

5

你可以像下面那样做

if (editor.selection.isCollapsed()) {
    var selRng = editor.selection.getRng();
    selRng.expand("word"); //expands the DOM range to the current word
    editor.selection.setRng(selRng);
}

下面是一个相同的 JS Fiddle

https://jsfiddle.net/t9qhmguo/

输出

于 2018-05-03T20:55:27.447 回答