Fix not determine OT have pending operations properly

This commit is contained in:
Wu Cheng-Han 2017-02-18 20:11:18 +08:00
parent f7149f5a83
commit 0aaa598130

View file

@ -2519,7 +2519,7 @@ var addStyleRule = (function () {
}()); }());
function updateAuthorshipInner() { function updateAuthorshipInner() {
// ignore when ot not synced yet // ignore when ot not synced yet
if (cmClient && Object.keys(cmClient.state).length > 0) return; if (havePendingOperation()) return;
authorMarks = {}; authorMarks = {};
for (var i = 0; i < authorship.length; i++) { for (var i = 0; i < authorship.length; i++) {
var atom = authorship[i]; var atom = authorship[i];
@ -2734,12 +2734,16 @@ var EditorClient = ot.EditorClient;
var SocketIOAdapter = ot.SocketIOAdapter; var SocketIOAdapter = ot.SocketIOAdapter;
var CodeMirrorAdapter = ot.CodeMirrorAdapter; var CodeMirrorAdapter = ot.CodeMirrorAdapter;
var cmClient = null; var cmClient = null;
var synchronized_ = null;
function havePendingOperation() {
return (cmClient && cmClient.state && cmClient.state.hasOwnProperty('outstanding')) ? true : false;
}
socket.on('doc', function (obj) { socket.on('doc', function (obj) {
var body = obj.str; var body = obj.str;
var bodyMismatch = editor.getValue() !== body; 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(); saveInfo();
if (setDoc && bodyMismatch) { if (setDoc && bodyMismatch) {
@ -2764,16 +2768,17 @@ socket.on('doc', function (obj) {
obj.revision, obj.clients, obj.revision, obj.clients,
new SocketIOAdapter(socket), new CodeMirrorAdapter(editor) new SocketIOAdapter(socket), new CodeMirrorAdapter(editor)
); );
synchronized_ = cmClient.state;
} else if (setDoc) { } else if (setDoc) {
if (bodyMismatch) { if (bodyMismatch) {
cmClient.undoManager.undoStack.length = 0; cmClient.undoManager.undoStack.length = 0;
cmClient.undoManager.redoStack.length = 0; cmClient.undoManager.redoStack.length = 0;
} }
cmClient.revision = obj.revision; cmClient.revision = obj.revision;
cmClient.setState(new ot.Client.Synchronized()); cmClient.setState(synchronized_);
cmClient.initializeClientList(); cmClient.initializeClientList();
cmClient.initializeClients(obj.clients); cmClient.initializeClients(obj.clients);
} else if (havePendingOperation) { } else if (havePendingOperation()) {
cmClient.serverReconnect(); cmClient.serverReconnect();
} }