google / diff-match-patch

Diff Match Patch is a high-performance library in multiple languages that manipulates plain text.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue: Code breaking when there is no change in a line

ravellaabhinav opened this issue · comments

Suppose if there are 5lines of code to check difference and there are changes in Line:1,2,5. The library is helping to print the difference with line number for line:1,2 and when there is a break in line number i.e.,line5 here line number is not getting printed instead char count number is being printed

Error:


image

@ravellaabhinav I'm having trouble undestanding what the issue is. From your screenshot, it looks like the library is providing the right indications of what changed in the text.

What is your specific question? What specifically are you seeing as broken? What specific output would you have expected differently?

@dmsnell, can you see in screenshot that it is showing 85 as line number in the difference, but there are only 7lines in the input

aha, thanks @ravellaabhinav - that's clear now, and I missed that.

what tool are you using there? the library itself doesn't really report line numbers, so that's why I was confused.

@dmsnell: That's my UI and nothing much.


I used the same logic:

function diff_lineMode(text1, text2) { var dmp = new diff_match_patch(); var a = dmp.diff_linesToChars_(text1, text2); var lineText1 = a.chars1; var lineText2 = a.chars2; var lineArray = a.lineArray; var diffs = dmp.diff_main(lineText1, lineText2, false); dmp.diff_charsToLines_(diffs, lineArray); return diffs; }

@ravellaabhinav this is a bit beyond me, and I'm guessing if you could share the code powering that UI it might help.

do you think it's possible there's a mismatch between what diff-match-patch is reporting and what is being interpreted as line counts?

what is the output of the call to diff-match-patch in the example behind the screenshot? can you paste the output directly here?