TinyMCE custom plugin, how to make a word automatically selected based on current cursor position?

时间:2018-04-18 18:06:06

标签: wordpress tinymce tinymce-4 tinymce-plugins

Making a custom plugin for TinyMCE, I wonder how to make a word automatically selected based on current cursor position, like in the the Wordpress "Add link" plugin.

I've searched the Wordpress TinyMCe Wplink code and TinyMCE Docs but I've got no reference....

1 个答案:

答案 0 :(得分:4)

你可以像下面这样做

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小提琴

https://jsfiddle.net/t9qhmguo/

Output