1

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);
Community
  • 1
  • 1
Fernando Gabrieli
  • 980
  • 3
  • 15
  • 31
  • Did you happen to find a solution for this? I have a similar issue (I think). I'm using an external custom toolbar and I'd like to trigger actions like bold/italic etc when those buttons are clicked. The problem is that as soon as I click outside the editor, the focus from the editable area is lost. What I tried doing is setting the focus back to the "active editor" before programatically calling the bold/italic functionality. Sadly the position of the cursor is reset to the beginning of the text. I'm kinda stuck and would greatly appreciate any help. :) – Rohit L Jan 19 '14 at 23:25

0 Answers0