Hi all,
I’m noticing that sometimes my backend is not able to rebuild the code the same way as the frontend. I think this is because codemirror uses dispatch to implement updates on the frontend, but in the backend you are stuck manipulating the document directly.
How I’m doing it in the backend:
let doc = Text.of(startingText.split("\n"));
for (const update of codeMirrorUpdates) {
try {
const updateObj = JSON.parse(update);
// console.log("updateObj", updateObj, "startingText", startingText);
let changes = ChangeSet.fromJSON(updateObj.changes);
console.log("changes", changes);
doc = doc.apply(changes);
} catch (error) {
console.log("one codemirror update broke");
}
}
return doc.toString();
How I’m doing it in the frontend:
this.view.dispatch(receiveUpdates(this.view.state, updates));
Note that I am using the @codemirror/collab in the frontend. I would assume that wouldn’t make a difference? Not sure though.
It would mean a lot if I could get this solved, thanks so much!