Heya, I’m making a extension for CodeMirror on Replit that shows modified and inserted lines via a gutter marker. The extension compares the current file contents to the file contents stored in the
HEAD commit snapshot. I’m making use of the
diff function exposed by
codemirror/merge, and it works really well, but it leaves some performance on the table as I have no way of incrementally updating the diff when the document changes (e.g. the user types something).
Here is a picture of the extension in action so it’s clear what I’m trying to do:
I’ve looked at the source for
codemirror/merge and noticed the internal
updateChunksB functions. I jankily modified my code to use
updateChunksB (which I copied out of the source just to try out) and I was able to see a decent performance improvement by using it.
With all of that context, I’m asking if you could export either:
updateChunksB(this is the simplest solution)
- a way to update a set of
Changeobjects, similar to
updateChunksB. I think this is a separate implementation from what
updateChunksdoes, but I might be naive here. My problem is that only one of my documents has changed and the other will never change. If the other changes, I’ll just recompute the diff. I’m figuring that this must simplify the rediff process, but I might be wrong.
I tried to see if I could do option 2 myself, but looking at the
updateChunks code made my head spin (did you figure that all out yourself? it’s impressive). I also tried to see if a
ChangeDesc based approach would work, which it does at first (with extremely high performance) but as you gradually update the document more and more the less of an actual diff it becomes, which I’m sure you’re aware of the reasons for.
One last tiny thing: I noticed that the
Chunk code uses
presentableDiff, but with my problem I actually don’t need the more human readable diff. I could eek out the tiniest bit more performance if I could use just
diff. I don’t think this really matters, but it’s just a tiny thing I noticed while looking at the code.