Drupal.editors.ckeditor.onChange() looks like this:
onChange: function (element, callback) {
var editor = CKEDITOR.dom.element.get(element).getEditor();
if (editor) {
var changed = function () {
callback(editor.getData());
};
// @todo Make this more elegant once http://dev.ckeditor.com/ticket/9794
// is fixed.
editor.on('key', changed);
editor.on('paste', changed);
editor.on('afterCommandExec', changed);
}
return !!editor;
},
As you can see, we're blocked on http://dev.ckeditor.com/ticket/9794 to get nicer and more reliable code there.
Sadly, editor.getData() does not yet contain the changes made by the latest keypress!
E.g.: the value is fooba. You type an 'r' at the end of this, now the visible value is foboar. But editor.getData() will still return fooba!
The temporary solution I found was to change the changed callback to wrap the call to editor.getData() in a window.setTimeout… not very nice, but it works for now:
var changed = function () {
window.setTimeout(function () {
callback(editor.getdata());
}, 0);
};
Comments
Comment #1
wim leersComment #2
wim leersComment #3
nod_Waiting on a better solution once ckeditor 4.2 ships. For now it works.
Comment #4
nod_meh.
Comment #5
alexpottThis solution is not nice but atm I can't see how we can get round this... so committed 2f1a280 and pushed to 8.x. Thanks!
Comment #6
wim leersIndeed :( But this will be fixed in the 4.2 release of CKEditor! :)