diffy icon indicating copy to clipboard operation
diffy copied to clipboard

Multiple character highlights blocks per line.

Open cirosantilli opened this issue 11 years ago • 3 comments

Input:

Diffy::Diff.new("a b c d e f g\n", "a B c D e F g\n").to_s(:html)

Output:

<div class="diff">
  <ul>
    <li class="del"><del>a <strong>b c d e f</strong> g</del></li>
    <li class="ins"><ins>a <strong>B c D e F</strong> g</ins></li>
  </ul>
</div>

Desired output (given a new option :html_multiple):

<div class="diff">
  <ul>
    <li class="del"><del>a <strong>b</strong> c <strong>d</strong> e <strong>f</strong> g</del></li>
    <li class="ins"><ins>a <strong>B</strong> c <strong>D</strong> e <strong>F</strong> g</ins></li>
  </ul>
</div>

This would make it possible to easily spot three modifications on a single long line. Currently it is only easy to spot the two corners.

Should be technically feasible, since git diff --color-words does it:

screenshot from 2014-07-19 11 39 34 git diff color words 3 words

cirosantilli avatar Jul 19 '14 13:07 cirosantilli

The current behavior is actually considered a feature of Diffy. (see http://www.drasticcode.com/2010/12/9/making-diffy-a-little-less-creative for an explanation). At the time I saw it as undesirable to allow single letter similarities inside otherwise highlighted lines.

IIRC You could tweak this behavior by removing or changing the if condition at https://github.com/samg/diffy/blob/master/lib/diffy/html_formatter.rb#L106-L107. I believe https://github.com/samg/diffy/commit/54089542f39352c95980197a45f41039d68a4208 added the "creativity suppression" feature.

It also might make sense to allow an option to configure this behavior.

samg avatar Jul 25 '14 04:07 samg

I see now, it's not very good. The best thing really would be to split up the line at a regex (spaces), and only then use the algorithm to highlight multiple changes, just like word diff. Let's consider this issue a proposal for that instead.

cirosantilli avatar Jul 25 '14 07:07 cirosantilli

Github just rolled this feature out: https://github.com/blog/1885-better-word-highlighting-in-diffs

cirosantilli avatar Sep 05 '14 22:09 cirosantilli