Good day to all.
Task - when loading data via ajax, you must place the received data as a quotation in the tinymce field and then move the cursor to the next line. I do this:

jsondata='<blockquote>'+jsondata+'</blockquote><p>&nbsp;</p>'; tinymce.execCommand('mceRemoveEditor', false, 'text-form'); tinyMCE.execCommand("mceAddEditor", false, 'text-form'); tinymce.get('text-form').setContent(jsondata); tinyMCE.execCommand("mceAddControl", false, 'text-form'); 

But the cursor is placed at the very beginning of the added line and does not transfer itself to the next. How to do? Tinymce version 4.2.5

  • Well in general - this is done through document.createRange() and window.getSelection() . Since the editor works through a div - contenteditable and otherwise set the position does not roll. - And

2 answers 2

Why not embed content through "mceInsertContent"? editor.execCommand ('mceInsertContent', false, jsondata);

In this case, the cursor automatically shifts to the end of the element.

     function enter(){ var fld = document.getElementById("fld"); fld.innerHTML = "hello\n"; fld.focus(); fld.selectionStart = fld.value.length; } 
     <button onclick="enter()">press</button> <br> <form> <textarea id="fld"> </textarea> </form>