collab_client: Redo server message queueing

Move server message queue processing out of `handleUserChanges()` for
the following reasons:
  * Fix a race condition: Before this change the client would stop
    processing incoming messages and stop sending changes to the
    server if a `NEW_CHANGES` message arrived while the user was
    composing a character and waiting for an `ACCEPT_COMMIT` message.
  * Improve readability: The `handleUserChanges()` function is for
    handling changes from the local user, not for handling changes
    from other users.
  * Simplify the code.
This commit is contained in:
Richard Hansen 2021-03-29 02:50:32 -04:00
parent e99fe88537
commit 63a1f078f4
3 changed files with 75 additions and 115 deletions

View file

@ -3504,16 +3504,7 @@ function Ace2Inner(editorInfo, cssManagers) {
const teardown = () => _teardownActions.forEach((a) => a());
let inInternationalComposition = false;
const handleCompositionEvent = (evt) => {
// international input events, fired in FF3, at least; allow e.g. Japanese input
if (evt.type === 'compositionstart') {
inInternationalComposition = true;
} else if (evt.type === 'compositionend') {
inInternationalComposition = false;
}
};
let inInternationalComposition = null;
editorInfo.ace_getInInternationalComposition = () => inInternationalComposition;
const bindTheEventHandlers = () => {
@ -3602,8 +3593,15 @@ function Ace2Inner(editorInfo, cssManagers) {
});
});
$(document.documentElement).on('compositionstart', handleCompositionEvent);
$(document.documentElement).on('compositionend', handleCompositionEvent);
$(document.documentElement).on('compositionstart', () => {
if (inInternationalComposition) return;
inInternationalComposition = new Promise((resolve) => {
$(document.documentElement).one('compositionend', () => {
inInternationalComposition = null;
resolve();
});
});
});
};
const topLevel = (n) => {