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....
You can do it like below
if (editor.selection.isCollapsed()) {
var selRng = editor.selection.getRng();
selRng.expand("word"); //expands the DOM range to the current word
editor.selection.setRng(selRng);
}
Below is a JS Fiddle for the same
https://jsfiddle.net/t9qhmguo/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With