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

Allow line breaks in side-by-side view #99

Open
jung-kim opened this issue Sep 11, 2016 · 32 comments
Open

Allow line breaks in side-by-side view #99

jung-kim opened this issue Sep 11, 2016 · 32 comments

Comments

@jung-kim
Copy link
Contributor

jung-kim commented Sep 11, 2016

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.

@rtfpessoa
Copy link
Owner

rtfpessoa commented Sep 13, 2016

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
Copy link
Owner

Related to #86

@thinkpozzitive
Copy link

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

@mohanapreeya
Copy link

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

@rtfpessoa
Copy link
Owner

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

@mohanapreeya
Copy link

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.

@hungdev
Copy link

hungdev commented Aug 27, 2019

@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.

@jung-kim
Copy link
Contributor Author

You mean wordwrap?

@hungdev
Copy link

hungdev commented Aug 27, 2019

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

@jung-kim
Copy link
Contributor Author

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.

@hungdev
Copy link

hungdev commented Aug 27, 2019

@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.

@jung-kim
Copy link
Contributor Author

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

@rtfpessoa rtfpessoa changed the title Changed row height from "wordwrap" isn't applied in side by side view Allow line breaks in side-by-side view Oct 5, 2019
@zabbixfan
Copy link

I really need this feature,please

@robertwalsh0
Copy link

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;
    }

@ccadek
Copy link

ccadek commented May 19, 2021

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

@rtfpessoa
Copy link
Owner

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

@NL33
Copy link

NL33 commented Jun 11, 2021

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.

@rtfpessoa
Copy link
Owner

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.

@mensfeld
Copy link

@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

@rtfpessoa
Copy link
Owner

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

@mensfeld
Copy link

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

@donaldpipowitch
Copy link

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;
     }

@skivol
Copy link

skivol commented Apr 18, 2022

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 👍

@rtfpessoa
Copy link
Owner

rtfpessoa commented May 7, 2022

@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?

@skivol
Copy link

skivol commented May 8, 2022

@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 🤔

@rtfpessoa
Copy link
Owner

Ahh, ok. That not needed

@abelpz
Copy link

abelpz commented Nov 6, 2022

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

@rtfpessoa
Copy link
Owner

👋 @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.

@abelpz
Copy link

abelpz commented Nov 13, 2022

@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.

@rtfpessoa
Copy link
Owner

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.

@jsonmorris
Copy link

jsonmorris commented Apr 17, 2024

Or I could just share the CSS, and someone else can give it a try.

@abelpz any way you could provide the CSS for defining the table width and word-wrap correctly for Side-by-side diffs?

@jsonmorris
Copy link

I achieved the wrap I needed for side-by-side diffs using the following CSS. Not sure if this breaks line-by-line, but looks like there are solutions for that above.

.d2h-code-line-ctn {
    white-space: pre-wrap;
    word-break: break-all;
}

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

No branches or pull requests