Question

Here is my issue :

I have a custom button with a code onClick. This code modify the selection's parent node, and I would like that my selection stays the same after my code, but tinyMCE disable my selection and give me a caret instead.

I tried getRng() and setRng from tinyMCE API but without success, the results are pretty odd. Sometimes it works and sometimes it deactivate my selection and give me a caret instead. Plus, sometimes it works only 2 times and then my button does not respond.

Here is my code which does not work:

 onclick : function() {
                range_selection = tinymce.activeEditor.selection.getRng();
                //Here is my own code which modify my parent node   
                tinymce.activeEditor.selection.setRng(range_selection);
                }
Était-ce utile?

La solution

Problem here is that this range is probably not applicable anymore because of a changed DOm structure. I would use a bookmark to overcome this issue:

var bookmark = ed.selection.getBookmark();

// do what you like to do here

ed.selection.`moveToBookmark`(bookmark);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top