diff options
author | Wu Cheng-Han | 2016-10-10 20:44:45 +0800 |
---|---|---|
committer | Wu Cheng-Han | 2016-10-10 20:44:45 +0800 |
commit | 521f76f7add074c4bbd200dc270cefc57e38f806 (patch) | |
tree | c11b2ab7f1e5b801f1986f038badd2e851b65946 | |
parent | c9f5cd49b0946b116a86fdd9cb4938a03fc96e1a (diff) |
Update to make OT error, client reconnect handling better and refactor client "doc" event
Diffstat (limited to '')
-rw-r--r-- | public/js/index.js | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/public/js/index.js b/public/js/index.js index 323da283..575baca2 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -2219,6 +2219,7 @@ socket.on('error', function (data) { var retryOnDisconnect = false; var retryTimer = null; socket.on('maintenance', function () { + cmClient.revision = -1; retryOnDisconnect = true; }); socket.on('disconnect', function (data) { @@ -2557,16 +2558,14 @@ socket.on('doc', function (obj) { obj = LZString.decompressFromUTF16(obj); obj = JSON.parse(obj); var body = obj.str; - var bodyMismatch = (editor.getValue() != body); + var bodyMismatch = editor.getValue() !== body; + var setDoc = !cmClient || (cmClient && cmClient.revision === -1) || obj.force; saveInfo(); - if (bodyMismatch) { - if (cmClient) - cmClient.editorAdapter.ignoreNextChange = true; - if (body) - editor.setValue(body); - else - editor.setValue(""); + if (setDoc && bodyMismatch) { + if (cmClient) cmClient.editorAdapter.ignoreNextChange = true; + if (body) editor.setValue(body); + else editor.setValue(""); } if (!loaded) { @@ -2575,12 +2574,8 @@ socket.on('doc', function (obj) { ui.content.fadeIn(); } else { //if current doc is equal to the doc before disconnect - if (bodyMismatch) - editor.clearHistory(); - else { - if (lastInfo.history) - editor.setHistory(lastInfo.history); - } + if (setDoc && bodyMismatch) editor.clearHistory(); + else if (lastInfo.history) editor.setHistory(lastInfo.history); lastInfo.history = null; } @@ -2589,7 +2584,7 @@ socket.on('doc', function (obj) { obj.revision, obj.clients, new SocketIOAdapter(socket), new CodeMirrorAdapter(editor) ); - } else { + } else if (setDoc) { if (bodyMismatch) { cmClient.undoManager.undoStack.length = 0; cmClient.undoManager.redoStack.length = 0; @@ -2600,7 +2595,7 @@ socket.on('doc', function (obj) { cmClient.initializeClients(obj.clients); } - if (bodyMismatch) { + if (setDoc && bodyMismatch) { isDirty = true; updateView(); } |