Skip to content

Commit

Permalink
Make copy/paste work for source code
Browse files Browse the repository at this point in the history
Fix regression casued by go-gitea#12047 so copy/paste works properly in all browsers.

Fixes go-gitea#12184

Also while looking at this I saw a small display issue for blame view. I think go-gitea#12023 was merged into original PR through an update branch before go-gitea#12047 was merged and made one of the css ruules not apply anymore.
  • Loading branch information
mrsdizzie committed Jul 8, 2020
1 parent dbd5e4b commit 4620c82
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
14 changes: 12 additions & 2 deletions modules/highlight/highlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ func File(numLines int, fileName string, code []byte) map[int]string {
m := make(map[int]string, numLines)
for k, v := range strings.SplitN(htmlbuf.String(), "\n", numLines) {
line := k + 1
m[line] = string(v)
content := string(v)
//need to keep lines that are only \n so copy/paste works properly in browser
if content == "" {
content = "\n"
}
m[line] = content
}
return m
}
Expand All @@ -143,7 +148,12 @@ func plainText(code string, numLines int) map[int]string {
m := make(map[int]string, numLines)
for k, v := range strings.SplitN(string(code), "\n", numLines) {
line := k + 1
m[line] = string(v)
content := string(v)
//need to keep lines that are only \n so copy/paste works properly in browser
if content == "" {
content = "\n"
}
m[line] = content
}
return m
}
2 changes: 1 addition & 1 deletion templates/repo/home.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{template "base/head" .}}
<div class="repository file list">
<div class="repository file list {{if .IsBlame}}blame{{end}}">
{{template "repo/header" .}}
<div class="ui container {{if .IsBlame}}fluid padded{{end}}">
{{template "base/alert" .}}
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/view_file.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<span id="L{{$line}}" data-line-number="{{$line}}"></span>
</td>
<td rel="L{{$line}}" class="lines-code chroma">
<pre><code>{{$code | Safe}}</code></pre>
<code>{{$code | Safe}}</code>
</td>
</tr>
{{end}}
Expand Down
4 changes: 4 additions & 0 deletions web_src/less/_base.less
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,10 @@ i.icon.centerlock {
}
}

.lines-code code {
white-space: pre;
}

.blame .lines-num {
padding: 0 !important;
background-color: #f5f5f5;
Expand Down

0 comments on commit 4620c82

Please sign in to comment.