fix: check hash before applying changes
Some checks failed
test / build-test (push) Has been cancelled
publish / build (arm64, arm64, macos-latest, darwin) (push) Has been cancelled
publish / build (x64, x64, ubuntu-latest, linux) (push) Has been cancelled
publish / build (x64, x64, windows-latest, win32) (push) Has been cancelled
publish / publish (push) Has been cancelled

This commit is contained in:
frelodev 2024-11-17 17:47:33 +01:00
parent aca566ab8e
commit c0682ec0ec

View file

@ -30,15 +30,6 @@ export async function apply_changes_to_buffer(path: string, controller: codemp.B
editor.document.positionAt(event.change.endIdx)
)
locks.set(path, event.change.content);
let success = await editor.edit(editBuilder => {
editBuilder
.replace(range, event.change.content)
});
if(success) controller.ack(event.version);
locks.delete(path);
if(!success) continue;
if (event.hash !== undefined) {
if (codemp.hash(editor.document.getText()) !== event.hash) {
if (autoResync) {
@ -56,6 +47,17 @@ export async function apply_changes_to_buffer(path: string, controller: codemp.B
}
}
}
locks.set(path, event.change.content);
let success = await editor.edit(editBuilder => {
editBuilder
.replace(range, event.change.content)
});
if(success) controller.ack(event.version);
locks.delete(path);
if(!success) continue;
}
singles.set(path, false);
}