I read What's the best way to set cursor/caret position?
and tried everything mentioned there but none of those solutions work for me.
I have a custom toolbar outside Tinymce.
So, when i hit a dropdown that i have that executes editor.formatter.apply('h1') (notice that i am clicking outside the editor when doing this, so it looses the focus) the caret no longer appears in the editor (this is the expected behavior).
Now, i want to restore the caret after applying the new format. I tried:
// I get the editor from the array for the example
var editor = tinymce.editors[0];
var range = editor.selection.getRng();
var node = range.startContainer;
range.setStart(node, 1);
range.setEnd(node, 1);
editor.selection.setRng(range);
editor.nodeChanged();
editor.focus();
It doesn't work.
If i set different offsets for the setStart and setEnd functions i see the text selected but i couldn't find a solution for making the caret/cursor show in the editor. With this i mean to restore the cursor in it, as if you click on a word to start typing.
This is what i was talking about above:
range.setStart(node, 1);
range.setStart(node, 3);