I'm just now updating out version of CKEditor from 3 to 4 and I have found that one of our custom plugins no longer works since there is no longer access to editor.textarea. Here's the old code that used to work in version 3:
var textArea = editor.textarea.$;
var start = textArea.selectionStart;
var end = textArea.selectionEnd;
var text = textArea.value;
textArea.value = text.substring(0, start) + sourceHtml + text.substring(end, text.length);
textArea.focus();
textArea.selectionStart = start;
textArea.selectionEnd = start + sourceHtml.length;
Note that "editor" is a reference to the ckeditor instance, and "sourceHtml" is html text that is being inserted.
I've tried looking through documentation and other threads, but can't seem to find the information I need to fix this. Basically, this code needs to work in source mode, and it needs to insert sourceHtml at cursor position (or replace currently selected piece of text with it), and then set the selection to the newly inserted text. There is already other logic that makes sure the insertion is valid, etc., I just need this piece to actually insert it. Any help would be appreciated.