From 015449832c8d437db975406d621d18b09fdf859e Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 22 Nov 2018 14:44:46 +0100 Subject: [PATCH] Fix missing characters caused by concurrent editing --- www/pad/inner.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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.