diff --git a/www/pad/inner.js b/www/pad/inner.js index 84da3c211..c1f3db7cd 100644 --- a/www/pad/inner.js +++ b/www/pad/inner.js @@ -694,6 +694,18 @@ define([ the first such keypress will not be inserted into the P. */ inner.addEventListener('keydown', cursor.brFix); + /* + CkEditor emits a change event when it detects new content in the editable area. + Our problem is that this event is sent asynchronously and late after a keystroke. + The result is that between the keystroke and the change event, chainpad may + receive remote changes and so it can wipe the newly inserted content (because + chainpad work synchronously), and the merged text is missing a few characters. + To fix this, we have to call `framework.localChange` sooner. We can't listen for + the "keypress" event because it is trigger before the character is inserted. + The solution is the "input" event, triggered by the browser as soon as the + character is inserted. + */ + inner.addEventListener('input', framework.localChange); editor.on('change', framework.localChange); // export the typing tests to the window.