Skip to content

Commit 12ee544

Browse files
silverwindzeripath
authored andcommitted
Fix wrapping long code lines in UI (#5927)
Wrapping was initially added in #2789 but it is currently disabled because the rule that applies wrapping to the wrap class did not have enough CSS specificity. Resolved the issue by using a general selector that matches all code boxes. The previous wrap class was removed because it had only been inconsistenly applied to various code boxes and because I found no easy way to add classes to code boxes rendered in Markdown. Also removed a seemingly useless :before on code view and added padding to restore the spacing.
1 parent af22df8 commit 12ee544

File tree

5 files changed

+11
-25
lines changed

5 files changed

+11
-25
lines changed

public/css/index.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/less/_base.less

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,15 @@ pre, code {
2727
line-height: 1.5;
2828
overflow: auto;
2929
}
30-
&.wrap {
31-
white-space: pre-wrap; /* CSS 3 */
32-
// white-space: -moz-normal; /* Mozilla, since 1999 */
33-
// white-space: -normal; /* Opera 4-6 */
34-
// white-space: -o-normal; /* Opera 7 */
35-
36-
-ms-word-break: break-all;
37-
word-break: break-all;
38-
39-
/* These are technically the same, but use both */
40-
overflow-wrap: break-word;
41-
word-wrap: break-word;
42-
}
30+
}
31+
/* Wrap long lines of code. This will also apply to Markdown code boxes. */
32+
pre > code {
33+
white-space: pre-wrap !important;
34+
word-break: break-all !important;
35+
overflow-wrap: break-word !important;
4336
}
4437
.dont-break-out {
45-
/* These are technically the same, but use both */
4638
overflow-wrap: break-word;
47-
word-wrap: break-word;
48-
49-
-ms-word-break: break-all;
5039
word-break: break-all;
5140

5241
/* Adds a hyphen where the word breaks, if supported (No Blink) */

public/less/_repository.less

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,10 @@
370370
padding: 0 !important;
371371
li {
372372
display: block;
373-
width: 100%;
373+
padding: 0 .25em;
374374
&.active {
375375
background: #ffffdd;
376376
}
377-
&:before {
378-
content: ' ';
379-
}
380377
}
381378
}
382379
}

templates/repo/diff/box.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
{{if and $.SignedUserID $line.CanComment $.PageIsPullFiles (not (eq .GetType 2))}}
128128
<a class="ui green button add-code-comment add-code-comment-left" data-path="{{$file.Name}}" data-side="left" data-idx="{{$line.LeftIdx}}">+</a>
129129
{{end}}
130-
<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
130+
<pre><code class="{{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
131131
</td>
132132
<td class="lines-num lines-num-new">
133133
<span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span>
@@ -137,7 +137,7 @@
137137
{{if and $.SignedUserID $line.CanComment $.PageIsPullFiles (not (eq .GetType 3))}}
138138
<a class="ui green button add-code-comment add-code-comment-right" data-path="{{$file.Name}}" data-side="right" data-idx="{{$line.RightIdx}}">+</a>
139139
{{end}}
140-
<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
140+
<pre><code class="{{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
141141
</td>
142142
</tr>
143143
{{if gt (len $line.Comments) 0}}

templates/repo/diff/section_unified.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
{{if and $.root.SignedUserID $line.CanComment $.root.PageIsPullFiles}}
2020
<a class="ui green button add-code-comment add-code-comment-{{if $line.RightIdx}}right{{else}}left{{end}}" data-path="{{$file.Name}}" data-side="{{if $line.RightIdx}}right{{else}}left{{end}}" data-idx="{{if $line.RightIdx}}{{$line.RightIdx}}{{else}}{{$line.LeftIdx}}{{end}}">+</a>
2121
{{end}}
22-
<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{$section.GetComputedInlineDiffFor $line}}</code></pre>
22+
<pre><code class="{{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{$section.GetComputedInlineDiffFor $line}}</code></pre>
2323
</td>
2424
</tr>
2525
{{if gt (len $line.Comments) 0}}

0 commit comments

Comments
 (0)