Skip to content

Commit 0aaa598

Browse files
committed
Fix not determine OT have pending operations properly
1 parent f7149f5 commit 0aaa598

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

public/js/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,7 +2519,7 @@ var addStyleRule = (function () {
25192519
}());
25202520
function updateAuthorshipInner() {
25212521
// ignore when ot not synced yet
2522-
if (cmClient && Object.keys(cmClient.state).length > 0) return;
2522+
if (havePendingOperation()) return;
25232523
authorMarks = {};
25242524
for (var i = 0; i < authorship.length; i++) {
25252525
var atom = authorship[i];
@@ -2734,12 +2734,16 @@ var EditorClient = ot.EditorClient;
27342734
var SocketIOAdapter = ot.SocketIOAdapter;
27352735
var CodeMirrorAdapter = ot.CodeMirrorAdapter;
27362736
var cmClient = null;
2737+
var synchronized_ = null;
2738+
2739+
function havePendingOperation() {
2740+
return (cmClient && cmClient.state && cmClient.state.hasOwnProperty('outstanding')) ? true : false;
2741+
}
27372742

27382743
socket.on('doc', function (obj) {
27392744
var body = obj.str;
27402745
var bodyMismatch = editor.getValue() !== body;
2741-
var havePendingOperation = cmClient && Object.keys(cmClient.state).length > 0;
2742-
var setDoc = !cmClient || (cmClient && (cmClient.revision === -1 || (cmClient.revision !== obj.revision && !havePendingOperation))) || obj.force;
2746+
var setDoc = !cmClient || (cmClient && (cmClient.revision === -1 || (cmClient.revision !== obj.revision && !havePendingOperation()))) || obj.force;
27432747

27442748
saveInfo();
27452749
if (setDoc && bodyMismatch) {
@@ -2764,16 +2768,17 @@ socket.on('doc', function (obj) {
27642768
obj.revision, obj.clients,
27652769
new SocketIOAdapter(socket), new CodeMirrorAdapter(editor)
27662770
);
2771+
synchronized_ = cmClient.state;
27672772
} else if (setDoc) {
27682773
if (bodyMismatch) {
27692774
cmClient.undoManager.undoStack.length = 0;
27702775
cmClient.undoManager.redoStack.length = 0;
27712776
}
27722777
cmClient.revision = obj.revision;
2773-
cmClient.setState(new ot.Client.Synchronized());
2778+
cmClient.setState(synchronized_);
27742779
cmClient.initializeClientList();
27752780
cmClient.initializeClients(obj.clients);
2776-
} else if (havePendingOperation) {
2781+
} else if (havePendingOperation()) {
27772782
cmClient.serverReconnect();
27782783
}
27792784

0 commit comments

Comments
 (0)