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....
答案 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/