mirror of
https://github.com/hexedtech/codemp-intellij.git
synced 2024-11-23 23:54:48 +01:00
feat: resync if hash mismatch
This commit is contained in:
parent
249a01d841
commit
db89c781a6
2 changed files with 14 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
|||
[versions]
|
||||
codemp = '0.7.0'
|
||||
codemp = '0.7.2'
|
||||
lombok = '1.18.34'
|
||||
intellij-plugin = '2.0.1'
|
||||
git-version = '3.1.0'
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.intellij.openapi.editor.Editor;
|
|||
import com.intellij.openapi.project.Project;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import mp.code.BufferController;
|
||||
import mp.code.Extensions;
|
||||
import mp.code.data.TextChange;
|
||||
import mp.code.exceptions.ControllerException;
|
||||
import mp.code.intellij.CodeMP;
|
||||
|
@ -46,20 +47,25 @@ public class BufferCallback implements Consumer<BufferController> {
|
|||
changeList.add(change);
|
||||
}
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(() ->
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
CommandProcessor.getInstance().executeCommand(
|
||||
this.project,
|
||||
() -> changeList.forEach((change) ->
|
||||
editor.getDocument().replaceString(
|
||||
(int) change.start, (int) change.end, change.content)
|
||||
),
|
||||
() -> changeList.forEach((change) -> {
|
||||
editor.getDocument().replaceString((int) change.start, (int) change.end, change.content);
|
||||
// check for validity, force-sync if mismatch
|
||||
if(change.hash.isPresent() && change.hash.getAsLong() != Extensions.hash(editor.getDocument().getText())) {
|
||||
try {
|
||||
editor.getDocument().setText(bufferController.getContent());
|
||||
} catch(ControllerException ignored) {} // ignore exception
|
||||
}
|
||||
}),
|
||||
"CodeMPBufferReceive",
|
||||
"codemp-buffer-receive",
|
||||
editor.getDocument()
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue