diff2html icon indicating copy to clipboard operation
diff2html copied to clipboard

Allow line breaks in side-by-side view

Open jung-kim opened this issue 8 years ago • 32 comments

Allow line breaks in side-by-side view to see the code without the need to scroll horizontally.

Check https://github.com/mohanapreeya/diff2html for an example.


Thank for a quick response on #97 and we do have word wrap working in default view but not in side by side view. Wordwrap view has always been challenging in side by side view but I figure I would use this time to describe the problem.

Side by side view with wordwrap is challenging because when word is wrapped in one table, that height needs to be applied to another table. For example, in below right table's words are wrapped and caused increase in row height but it cannot be easily be applied to left table as they are separate table.

screen shot 2016-09-11 at 15 06 32

Will it be easy to place them in a same table so we can easily do this without JS? I feel like this will not be a trivial change and I think this maybe not be a critical issue.

jung-kim avatar Sep 11 '16 22:09 jung-kim

That is probably the biggest layout problem. Even for the line-by-line view it is hard to get the breaks correctly.

For the side-by-side, having only one table, I am not sure if you can make the widths and the overflows work, and even harder to have horizontal scroll working.

If you have any suggestions. I can take a look, but this is quite difficult.

rtfpessoa avatar Sep 13 '16 12:09 rtfpessoa

Related to #86

rtfpessoa avatar Oct 16 '16 00:10 rtfpessoa

@codingtwinky what changes did you make in order to get "word wrap working in default view"? Can you show me an example?

thinkpozzitive avatar Jan 05 '17 16:01 thinkpozzitive

I have solved this issue in my worspace with some new template files and code changes. I would like to contribute my changes.

mohanapreeya avatar Sep 21 '18 10:09 mohanapreeya

@mohanapreeya that would be nice. Can I check the working version somewhere?

rtfpessoa avatar Sep 21 '18 13:09 rtfpessoa

I have a temporary output in this fork https://github.com/mohanapreeya/diff2html.git. You can view the output in demo page. Source code changes are in the same repository.

mohanapreeya avatar Sep 24 '18 10:09 mohanapreeya

@jung-kim could you tell me how to break word like your image? i don't need make it side by side. please tell me.

hungdev avatar Aug 27 '19 10:08 hungdev

You mean wordwrap?

jung-kim avatar Aug 27 '19 16:08 jung-kim

@jung-kim yes, which class should i override overflow-wrap: break-word;? or how do i do to make like your image?

hungdev avatar Aug 27 '19 16:08 hungdev

I'm bit confused on what you mean by "like your image". I presume you mean the green text on the right side and if that is correct break-word is the correct one.

jung-kim avatar Aug 27 '19 16:08 jung-kim

@jung-kim no, my mean break the work if the sentence too long. look at the online example: https://stackblitz.com/edit/react-em2guv i dont want to horizontal scroll, i want to break line.

hungdev avatar Aug 27 '19 16:08 hungdev

Green text on the right side is the one with line break isn't it? Either way, pick whatever settings within wordwrap that can help you

jung-kim avatar Aug 27 '19 16:08 jung-kim

I really need this feature,please

zabbixfan avatar Oct 25 '19 07:10 zabbixfan

Not sure if this works in side-by-side but in line-by-line you can get the lines to wrap by changing the following css

    .d2h-code-line, .d2h-code-line-ctn {
      white-space: normal;
    }

robertwalsh0 avatar Apr 29 '20 18:04 robertwalsh0

@robertwalsh0 This CSS does work in side-by-side view as well.

ccadek avatar May 19 '21 13:05 ccadek

I cannot replicate this, can you provide a working example?

rtfpessoa avatar May 21 '21 20:05 rtfpessoa

New to diff2html. It seems awesome. Thanks for the great work putting it together over the years.

Is there currently a working way to have text wrap with any of diff2html's formats?

I note that if I use diff2html on a diff, without including the mandatory html resource inputs:

<!-- CSS -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/diff2html/bundles/css/diff2html.min.css" />

<!-- Javascripts -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/diff2html/bundles/js/diff2html-ui.min.js"></script>

Then the resulting display from this code:

const Diff2html = require('diff2html');
const diffJson = Diff2html.parse([DIFF STRING TO BE DISPLAYED];
const diffHtml = Diff2html.html(diffJson, { drawFileList: true  });
document.getElementById('showTheDiff').innerHTML = diffHtml

Shows the changes with the text word-wrapped in my app. Of course, it doesn't have the color highlighting that the mandatory html resource inputs have, but I wonder if I can just add that with some css manually.

NL33 avatar Jun 11 '21 15:06 NL33

Is there currently a working way to have text wrap with any of diff2html's formats?

No, I could not find a way that does not break something else.

rtfpessoa avatar Jul 09 '21 21:07 rtfpessoa

@rtfpessoa could you point out what were the problems, I did really bad POC but this looks sooo good (not side by side):

Zrzut ekranu z 2021-09-17 13-05-01

mensfeld avatar Sep 17 '21 11:09 mensfeld

@mensfeld the problem is in the side-by-side diff. Can you make that work for side-by-side too?

rtfpessoa avatar Sep 18 '21 20:09 rtfpessoa

@rtfpessoa I can give it a shot in 1-2 weeks but I'm not an expert and my solution is rather clumsy.

mensfeld avatar Sep 18 '21 20:09 mensfeld

Not sure if this works in side-by-side but in line-by-line you can get the lines to wrap by changing the following css

    .d2h-code-line, .d2h-code-line-ctn {
      white-space: normal;
    }

Thanks for the hint. I got even better results with this as leading whitespace in a line will be preserved:

     .d2h-code-line, .d2h-code-line-ctn {
       white-space: pre-wrap;
     }

donaldpipowitch avatar Feb 10 '22 07:02 donaldpipowitch

Taking ideas from this thread (thanks for those :) ) and also overriding original "width: 100%" in some classes (which probably doesn't work well inside table cells, in combination with padding):

.d2h-code-line-ctn {
	white-space: normal;
}
.d2h-code-line, .d2h-code-side-line, .d2h-code-line-ctn {
	width: revert;
}

to avoid overflow problems like on the image below: example

And things seem to look quite good 👍

skivol avatar Apr 18 '22 17:04 skivol

@skivol do you think you could send a full spec with all the changes required to get this to work in both side-by-side and line-by-line?

rtfpessoa avatar May 07 '22 20:05 rtfpessoa

@rtfpessoa you mean the full source code of the html template which I used for the purpose (with css styles which were mentioned in the comment above) ? Can do that, but not sure if the quality of the results is sufficient for general usage (specifically in regards to the alignment of the lines to the left and right which is a bit worse when wrapping the lines, but the benefit is that everything is visible without the need to scroll horizontally).

image

I guess one could try to display both sides in one table (possibly with rowspan for changesets which differ in number of rows) in an attempt to be able to do the wrapping and keep the alignment 🤔

skivol avatar May 08 '22 19:05 skivol

Ahh, ok. That not needed

rtfpessoa avatar Jun 03 '22 22:06 rtfpessoa

@rtfpessoa is there an open PR on this? I got it working with some CSS changes.

abelpz avatar Nov 06 '22 16:11 abelpz

👋 @abelpz no, I could never get it working properly.

If you got it working in both ways, would be good if we could offer both options (with and without line breaks) maybe by applying a different css classes.

rtfpessoa avatar Nov 12 '22 12:11 rtfpessoa

@rtfpessoa it does work for both side-by-side and line-by-line, I could try to add that if you want, this is what I propose:

  • Add one config option to set the default mode: wordWrap: true
  • Add a button somewhere in the UI to toggle this feature.

If you point me to the files I should look at to add this, I can make a PR. Or I could just share the CSS, and someone else can give it a try.

abelpz avatar Nov 13 '22 03:11 abelpz

I am not sure this can be done with a single file change.

The code starts in diff2html.ts. You need to add the css in diff2html.css and then somehow apply the class change when rendering maybe by passing the boolean to the templates.

You can test if it works by running yarn validate and then opening the docs/demo.html file generated which will use the code you changed.

rtfpessoa avatar Jan 01 '23 22:01 rtfpessoa