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);
      };
Files: 
CommentFileSizeAuthor
#1 1995730-1.patch712 bytesWim Leers
PASSED: [[SimpleTest]]: [MySQL] 55,966 pass(es).
[ View ]

Comments

Wim Leers’s picture

Status:Active» Needs review
StatusFileSize
new712 bytes
PASSED: [[SimpleTest]]: [MySQL] 55,966 pass(es).
[ View ]
Wim Leers’s picture

Issue tags:+sprint, +Spark
nod_’s picture

Status:Needs review» Reviewed & tested by the community
Issue tags:-sprint, -Spark

Waiting on a better solution once ckeditor 4.2 ships. For now it works.

nod_’s picture

Issue tags:+sprint, +Spark

meh.

alexpott’s picture

Status:Reviewed & tested by the community» Fixed

This 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!

Wim Leers’s picture

Issue tags:-sprint

Indeed :( But this will be fixed in the 4.2 release of CKEditor! :)

Automatically closed -- issue fixed for 2 weeks with no activity.