0

Currently I am developing a plugin for TinyMce 4's editor. In this plugin I need to know whether the cursor is located in/around a word.

The best way to determine this would be to check both the character before and after the cursor. If both are either empty or whitespace then the cursor is not contained in a word.

However now how do I translate this to code? The editor.selection is probably the way to go (http://www.tinymce.com/wiki.php/api4:class.tinymce.dom.Selection) but I have no clue as to how I can accomplish this. I was not able to find any examples.

Roel van Duijnhoven
  • 800
  • 1
  • 7
  • 24

1 Answers1

0

TinyMCE works mostly with selections or nodes, and as far as I can se only has a function for setting the cursor offset within a node, not getting it. But maybe you could try and see what output this gives you:

// Alerts the currently selected contents as plain text
alert(tinymce.activeEditor.selection.getContent({format: 'text'}));

And have a look at these functions http://www.tinymce.com/wiki.php/api4:class.tinymce.dom.Selection

Christoffer Bubach
  • 1,676
  • 3
  • 17
  • 45
  • That functions returns nothing if I have not selected anything. I want it to return the word the cursor is in (even if I did not select it). The functions in the link I was aware of (I put the link in my opening post :)). I did not see any method in there that could help. Thanks for your effort though! – Roel van Duijnhoven Aug 15 '13 at 06:40