diff options
author | Wu Cheng-Han | 2015-09-25 13:59:28 +0800 |
---|---|---|
committer | Wu Cheng-Han | 2015-09-25 13:59:28 +0800 |
commit | ab6deb8e2ec7d99001ec22e8491a373495667852 (patch) | |
tree | 2dd972cec5ddc6adffeb194f3370cb8e953ea780 | |
parent | 9acd07058169b7b6a2ef700f7b671a06b77a0340 (diff) |
Fixed when doc reconnect might get wrong OT operation, reorder initialize instructions in proper sequence
-rw-r--r-- | public/js/index.js | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/public/js/index.js b/public/js/index.js index 199be888..d470776f 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -998,6 +998,18 @@ socket.on('refresh', function (data) { lastchangeui = ui.infobar.lastchange; updateLastChange(); checkPermission(); + if (!loaded) { + changeMode(currentMode); + loaded = true; + emitUserStatus(); //send first user status + updateOnlineStatus(); //update first online status + setTimeout(function () { + //work around editor not refresh or doc not fully loaded + windowResizeInner(); + //work around might not scroll to hash + scrollToHash(); + }, 1); + } }); var EditorClient = ot.EditorClient; @@ -1013,43 +1025,18 @@ socket.on('doc', function (obj) { saveInfo(); if (bodyMismatch) { + if (cmClient) + cmClient.editorAdapter.ignoreNextChange = true; if (body) editor.setValue(body); else editor.setValue(""); } - if (!cmClient) { - cmClient = window.cmClient = new EditorClient( - obj.revision, obj.clients, - new SocketIOAdapter(socket), new CodeMirrorAdapter(editor) - ); - } else { - cmClient.revision = obj.revision; - cmClient.initializeClients(obj.clients); - if (bodyMismatch) { - cmClient.undoManager.undoStack.length = 0; - cmClient.undoManager.redoStack.length = 0; - } - } if (!loaded) { editor.clearHistory(); ui.spinner.hide(); ui.content.fadeIn(); - changeMode(); - loaded = true; - emitUserStatus(); //send first user status - updateOnlineStatus(); //update first online status - setTimeout(function () { - //work around editor not refresh - editor.refresh(); - //work around cursor not refresh - for (var i = 0; i < onlineUsers.length; i++) { - buildCursor(onlineUsers[i]); - } - //work around might not scroll to hash - scrollToHash(); - }, 1); } else { //if current doc is equal to the doc before disconnect if (bodyMismatch) @@ -1061,6 +1048,22 @@ socket.on('doc', function (obj) { lastInfo.history = null; } + if (!cmClient) { + cmClient = window.cmClient = new EditorClient( + obj.revision, obj.clients, + new SocketIOAdapter(socket), new CodeMirrorAdapter(editor) + ); + } else { + if (bodyMismatch) { + cmClient.undoManager.undoStack.length = 0; + cmClient.undoManager.redoStack.length = 0; + } + cmClient.revision = obj.revision; + cmClient.setState(new ot.Client.Synchronized()); + cmClient.initializeClientList(); + cmClient.initializeClients(obj.clients); + } + if (bodyMismatch) { isDirty = true; updateView(); |