Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange lines get inserted in the wrong place or diff computed wrong #28

Closed
jackanderson opened this issue Feb 23, 2018 · 5 comments · Fixed by #38
Closed

Strange lines get inserted in the wrong place or diff computed wrong #28

jackanderson opened this issue Feb 23, 2018 · 5 comments · Fixed by #38

Comments

@jackanderson
Copy link

jackanderson commented Feb 23, 2018

Im not sure what is causing the issue, but ive seen several cases where doing a copy actually results in new differences. ive attached two files that you can paste into the respective editors. copy the difference in the fileb side to the filea side and you'll see a new difference is then created for the blank line after the original difference. Not sure if this is line ending related or diff related?

fileb.txt
filea.txt

@JackuB
Copy link
Collaborator

JackuB commented Feb 25, 2018

I think I know how to fix, but I’m currently travelling so I could get to it in a few days.

Possibly related to #1

JackuB added a commit that referenced this issue Feb 25, 2018
@jackanderson
Copy link
Author

jackanderson commented Feb 26, 2018

hmm. nope. that didnt fix the issue. I still get a new difference after copying. It's like it's not initially detecting the blank line as a difference and then once the first difference is resolved then it detects it as a difference. Maybe something to do with the diff simplifier?

@JackuB
Copy link
Collaborator

JackuB commented Mar 8, 2018

Still travelling, but managed to create the smallest possible repro:

start

something else

end

and

starts
mid
end

I will be looking into why this is happening. Pushed the branch here for now https://github.com/ace-diff/ace-diff/tree/JackuB/merge-with-newlines

@JackuB JackuB mentioned this issue Apr 6, 2018
@JackuB
Copy link
Collaborator

JackuB commented Apr 19, 2018

The issue is with newlines - if you look at the raw output from https://github.com/JackuB/diff-match-patch there is \nend (0 means no change, so it's not part of the patch that's applied)
snimek obrazovky 2018-04-19 v 17 04 16

If you manually move the \n to the previous line 42b957e it would fix the diffing, as now the newline will be part of the patch.

2018-04-19 17_52_12

I think it might be related to this behaviour:

ace-diff/src/index.js

Lines 494 to 497 in 42b957e

// this was added in to hack around an oddity with the Google lib. Sometimes it would include a newline
// as the first char for a diff, other times not - and it would change when you were typing on-the-fly. This
// is used to level things out so the diffs don't appear to shift around
let newContentStartsWithNewline = /^\n/.test(diffText);

@jackanderson
Copy link
Author

jackanderson commented Apr 19, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants