I am making a little word prediction plugin for tinyMCE and need to extract a bit of text and later insert text from a list of predicted words. The insertion should be no problem, as I know where the cursor is and can use the mceInsertContent
command. Getting the text for the prediction however...
I need to extract a subset of the text ending at the letter immediately before the cursor position and starting at, well, the start of the text. I can strip HTML tags myself if neccessary, but I prefer letting tinyMCE do it if possible.
I was thinking of doing it like this:
- Insert bookmark at current cursor positon using
mceInsertContent
- Create a range from start of text up to my bookmark.
- Get the content of the range.
- Delete the bookmark.
Now, since I'm not that well versed in tinyMCE that has proved to be a bit of a challenge for me, so how would one go about doing this?
The code needs to work cross-browser.