diff --git a/lib/client/edit.js b/lib/client/edit.js index bdd71634..a2a00954 100644 --- a/lib/client/edit.js +++ b/lib/client/edit.js @@ -82,27 +82,30 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M onSave(msg); }); - socket.on('patch', function(name, data, hashFS) { + socket.on('patch', function(name, data, hash) { if (name === Info.path) loadDiff(function(error) { - if (error) { + if (error) Util.log(error); - } else { - sha(function(error, hash) { - var value, cursor; + else + DOM.Storage.get(name + '-hash', function(error, hashLocal) { + var cursor, value; - if (hash === hashFS) { + if (hash === hashLocal) { + cursor = Ace.selection.getCursor(), value = Edit.getValue(); value = Diff.applyPatch(value, data); - cursor = Ace.selection.getCursor(); Ace.setValue(value); - Ace.clearSelection(); - Ace.moveCursorTo(cursor.row, cursor.column); - Ace.scrollToLine(cursor.row, true); + + sha(function(error, hash) { + DOM.saveDataToStorage(name, value, hash); + Ace.clearSelection(); + Ace.moveCursorTo(cursor.row, cursor.column); + Ace.scrollToLine(cursor.row, true); + }); } }); - } }); });