feature(edit) patch: add socket sync

This commit is contained in:
coderaiser 2014-11-11 02:55:04 -05:00
parent a516ee7b37
commit 96419627e6

View file

@ -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);
});
}
});
}
});
});