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

unexpected diffchars result #514

Closed
void285 opened this issue Apr 3, 2024 · 3 comments
Closed

unexpected diffchars result #514

void285 opened this issue Apr 3, 2024 · 3 comments

Comments

@void285
Copy link

void285 commented Apr 3, 2024

Hi, this is unexpected:

let old = 'abddefg';
let new = 'abcdefg';
let diff = Diff.diffChars(old, new);
console.log(diff);

expected:
image

but got:
image

Is there any option to achieve the expected result? Thanks.

@ExplodingCabbage
Copy link
Collaborator

No, there's no option that will achieve the result you want here; the result jsdiff gives is the one that the Myers diff algorithm, implemented as described in Myers's paper, gives. I'm not totally opposed to concrete proposals about options for tweaking this, but I'm not sure what such an option would look like (nor indeed what underlying rule you're envisaging that makes your "expected" output here be, well, expected).

@ExplodingCabbage ExplodingCabbage closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 2024
@kerams
Copy link

kerams commented Apr 29, 2024

nor indeed what underlying rule you're envisaging that makes your "expected" output here be, well, expected

The Levenshtein distance between the two strings is 1, so a diff would ideally contain a single substitution (i.e. insertion and deletion at the same index).

@ExplodingCabbage
Copy link
Collaborator

@kerams aha - you're thinking in terms of substitutions! Okay, #475 is the issue that would give you what you want, then - but it'd be a drastic addition of an entirely new algorithm to the library. The Myers diff algorithm has no concept of substitutions - only of insertions and deletions - which is why it sees the two diffs in @void285's post as having equal edit distance.

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

No branches or pull requests

3 participants