From c0682ec0ec57a07650dfa3a6812b54f00dde5054 Mon Sep 17 00:00:00 2001 From: frelodev Date: Sun, 17 Nov 2024 17:47:33 +0100 Subject: [PATCH] fix: check hash before applying changes --- src/commands/buffers.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/commands/buffers.ts b/src/commands/buffers.ts index b7080e0..0898e2e 100644 --- a/src/commands/buffers.ts +++ b/src/commands/buffers.ts @@ -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); }