Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting start and end of selected text from tinyMCE

I have configured the tinyMCE editor with a custom context menu. When I right-click on any word in the editor, the chosen word gets highlighted. I am able to get the selected text with editor.selection.getContent().

  1. How do I get the start and end points of the selected text within the entire text that is currently in the tinyMCE editor? I tried editor.selection.getStart() and getEnd(), but that has not yielded enough results.

My task is to take the start and end indices and get the previous word with it. I am currently using tinymce-3.5.10.

like image 549
Sriram Avatar asked Dec 29 '25 16:12

Sriram


1 Answers

You will need to use

var range = editor.selection.getRng()

to get a range. You can get the start- and end-container using

range.startContainer
range.endContainer
like image 70
Thariama Avatar answered Dec 31 '25 06:12

Thariama