summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorWu Cheng-Han2017-02-18 20:11:18 +0800
committerWu Cheng-Han2017-02-18 20:11:18 +0800
commit0aaa59813018847c765624bcd8cfa22e9aa57284 (patch)
tree3ed2b3ec6470488e88d3e3ff91db46f822587256 /public
parentf7149f5a834ea79ec82f04ef2da257fe72f1b330 (diff)
Fix not determine OT have pending operations properly
Diffstat (limited to '')
-rw-r--r--public/js/index.js15
1 files changed, 10 insertions, 5 deletions
diff --git a/public/js/index.js b/public/js/index.js
index 3ad79d59..f0c476ef 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -2519,7 +2519,7 @@ var addStyleRule = (function () {
}());
function updateAuthorshipInner() {
// ignore when ot not synced yet
- if (cmClient && Object.keys(cmClient.state).length > 0) return;
+ if (havePendingOperation()) return;
authorMarks = {};
for (var i = 0; i < authorship.length; i++) {
var atom = authorship[i];
@@ -2734,12 +2734,16 @@ var EditorClient = ot.EditorClient;
var SocketIOAdapter = ot.SocketIOAdapter;
var CodeMirrorAdapter = ot.CodeMirrorAdapter;
var cmClient = null;
+var synchronized_ = null;
+
+function havePendingOperation() {
+ return (cmClient && cmClient.state && cmClient.state.hasOwnProperty('outstanding')) ? true : false;
+}
socket.on('doc', function (obj) {
var body = obj.str;
var bodyMismatch = editor.getValue() !== body;
- var havePendingOperation = cmClient && Object.keys(cmClient.state).length > 0;
- var setDoc = !cmClient || (cmClient && (cmClient.revision === -1 || (cmClient.revision !== obj.revision && !havePendingOperation))) || obj.force;
+ var setDoc = !cmClient || (cmClient && (cmClient.revision === -1 || (cmClient.revision !== obj.revision && !havePendingOperation()))) || obj.force;
saveInfo();
if (setDoc && bodyMismatch) {
@@ -2764,16 +2768,17 @@ socket.on('doc', function (obj) {
obj.revision, obj.clients,
new SocketIOAdapter(socket), new CodeMirrorAdapter(editor)
);
+ synchronized_ = cmClient.state;
} else if (setDoc) {
if (bodyMismatch) {
cmClient.undoManager.undoStack.length = 0;
cmClient.undoManager.redoStack.length = 0;
}
cmClient.revision = obj.revision;
- cmClient.setState(new ot.Client.Synchronized());
+ cmClient.setState(synchronized_);
cmClient.initializeClientList();
cmClient.initializeClients(obj.clients);
- } else if (havePendingOperation) {
+ } else if (havePendingOperation()) {
cmClient.serverReconnect();
}