Closed VasylMarchuk closed 1 week ago
There are often multiple valid diffs for a given pair of documents, and the one the library found here is definitely also valid. That being said, it does try to align changes to line boundaries, and attached patch fixes the issue that made it fail to do so here.
Thank you @marijnh, I can conform that updating @codemirror/merge
from 6.7.2
to 6.7.4
does fix the most obvious mis-behaviours of the diff algorithm for us, so that commit did help, big thanks again, our diffs look much cleaner now!
Before:
After:
PS: it also appears that the accept/reject buttons of the mergeControls
option are now missing for line insertions, but luckily we aren't using those yet.
Describe the issue
When a new line is inserted into the document, the diff algorithm marks the line it was inserted before as deleted & re-inserted later.
Example
If I have a document:
and then I insert a new line:
... it will mark
An example plain-text document 8
as deleted & re-inserted later:Details
What's more interesting, it treats the lines that don't start similarly correctly, such as line 11
NEW LINE
:What is even more interesting, this also strangely depends on what's LATER in the diff... but not always... the topmost "glitch" remains even after no more changes below, this video demonstrates it perfectly:
https://github.com/user-attachments/assets/084a8ade-7cf3-4a0e-950d-80754b2b32a4
Summary
So, to summarize what happens in the video above:
An example plain-text document NEW LINE
betweenAn example plain-text document 7
andAn example plain-text document 8
results inAn example plain-text document 8
treated as removed, re-insertedNEW LINE
between 9 & 10 doesn't do thatAn example plain-text document NEW LINE
between 21 & 22 does that againNEW LINE
is ACCEPTEDDocument used in the video, to reproduce:
Reproduction link
We have a complete functioning demo of CodeMirror, wrapped into an Ember.js component over at https://app.codecrafters.io/demo/code-mirror, configurable with most of the standard extensions & their options in realtime, please feel free to test over there. It's ok if people discover the link here on GitHub, but please don't link to it, yet :)
All of the documents used as examples in the Demo's
document
drop-down can be found here. The Ember.js component itself, which wraps CodeMirror, passes it all enabled extensions, and handles updates is here, just in case.Our current CodeMirror & Merge versions