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

Flip added and removed order? #14

Closed
jacobsandlund opened this issue Oct 26, 2012 · 8 comments
Closed

Flip added and removed order? #14

jacobsandlund opened this issue Oct 26, 2012 · 8 comments

Comments

@jacobsandlund
Copy link

I'm wondering if it would make sense to flip the order in which added vs removed change objects get returned diffLines. This would make it easier to make a "git-like" diff without having to swap the added and removed semantics.

This is what I'm doing right now for Vaccine:

var chunks = jsdiff.diffLines(next, old).map(function(d) {
  if (d.removed) {
    return '<span class="added">' + prepend(d.value, '+') + '</span>';
  } else if (d.added) {
    return '<span class="removed">' + prepend(d.value, '-') + '</span>';
  } else {
    return prepend(d.value, ' ');
  }
});
return chunks.join('\n');
@mathiasrw
Copy link

I am using this approach - hope it can help others...

var words = JsDiff.diffWords(a,b)

for(var j = 0; j<words.length;j++){
    if((words[j].added || words[j].removed) && j+1 < words.length  && (words[j+1].added || words[j+1].removed)){
        var tmp = words[j]
        words[j] = words[j+1] 
        words[j+1] = tmp
    }
}

@runemadsen
Copy link

+1 on this. I use this lib to generate unified diffs that would normally come from Git, and they always append the deletion before the addition. The unified diff syntax explanation here seems to suggest so too:
http://en.wikipedia.org/wiki/Diff#Unified_format

(and hi @mathiasrw).

@adiroiban
Copy link

+1 on this. thanks!

@monsanto
Copy link

+1 this was surprising to me

@nylen
Copy link

nylen commented Apr 8, 2015

+1 to this, as a result mocha displays diffs in the reverse order from standard tools like diff and git.

@kpdecker
Copy link
Owner

kpdecker commented May 6, 2015

Released in 1.4.0

@nylen
Copy link

nylen commented May 7, 2015

👍 thanks!!

@mathiasrw
Copy link

Yayyyy :)

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

7 participants