mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
feature(edit) patch: add socket sync
This commit is contained in:
parent
a516ee7b37
commit
96419627e6
1 changed files with 14 additions and 11 deletions
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue