I’m trying to automatically insert a bar (|) and then move the cursor to the position that is just before the new inserted bar, so for example I have the following text in the editor:
Line 1
Line 2 starts here | there can be other text
After this bar is typed then the following code runs, and I want to get 2 bars but with the cursor between them eg:
Line 2 starts here || there can be other text (with the cursor between the 2 bars)
What I’m trying to do is create an span node in the actual caret position (which is just after the first typed bar), then insert the new bar and finally set the location to the new span, but it is simply not working.
//I put the code in a setTimeOut to better testing
setTimeout(function () {
var editor = tinymce.activeEditor;
var node = editor.dom.create('span', {}, '');
editor.selection.setNode(node);
editor.execCommand('mceInsertContent', false, "|");
editor.selection.setCursorLocation(node, 0);
}, 2000);
Any help is appreciated, thanks in advance.