Author | Jakob Wakeling <[email protected]> |
Date | 2023-11-16 08:28:16 |
Commit | a778a391f6d44c4af7d07f1e5784d4fbf2638267 |
Parent | 08dff9acdd4ef4de7329c7c47778449035488d55 |
Don't select line numbers with text in file view
Diffstat
M | res/repo/file.html | | | 16 | +++++++++------- |
M | res/style.css | | | 5 | +++-- |
M | src/repo/file.go | | | 4 | +++- |
3 files changed, 15 insertions, 10 deletions
diff --git a/res/repo/file.html b/res/repo/file.html index d18ce17..271e647 100644 --- a/res/repo/file.html +++ b/res/repo/file.html @@ -6,14 +6,16 @@ {{.File}} ({{.Size}}) {{.Mode}} </header><hr> <main> - <table class="highlight-row"> + <table> {{if .Lines}} - {{range $i, $l := .Lines}} - <tr id="{{$i}}"> - <td class="lnum" style="text-align: right;"><a href="#{{$i}}">{{$i}}</a></td> - <td class="line">{{$l}}</td> - </tr> - {{end}} + <tr> + <td class="lnum" style="text-align: right;"> + <pre>{{range $i, $l := .Lines}}<a id="{{$i}}" href="#{{$i}}">{{$i}}</a>{{end}}</pre> + </td> + <td class="line"> + <pre>{{.Body}}</pre> + </td> + </tr> {{else}} <tr><td>Binary file</td></tr> {{end}} diff --git a/res/style.css b/res/style.css index 0bd3552..2578fd7 100644 --- a/res/style.css +++ b/res/style.css @@ -8,13 +8,14 @@ hr { border: 0; height: 1rem; margin: 0; } table td { padding: 0 0.4rem; } table td:empty::after { content: "\00a0"; } +table td pre { margin: 0; } .highlight-row tr:hover td { background-color: #222222; } -table td.lnum { padding: 0; } +table td.lnum { padding: 0; vertical-align: top; } table td.lnum a { color: inherit; display: block; padding: 0 0.4rem 0 0.8rem; } table td.lnum a:hover { text-decoration: none; } -table td.line { tab-size: 4; white-space: pre; } +table td.line { tab-size: 4; vertical-align: top; } table input { border: 2px solid #333333; border-radius: 3px; background-color: #111111; padding: 2px; } table input[type="text"] { color: #888888; width: 24em; } diff --git a/src/repo/file.go b/src/repo/file.go index 334a7a7..da2651c 100644 --- a/src/repo/file.go +++ b/src/repo/file.go @@ -40,6 +40,7 @@ func HandleFile(w http.ResponseWriter, r *http.Request) { Readme, Licence string Mode, File, Size string Lines []string + Body string Editable bool }{ Title: repo.Name + " - File", Name: repo.Name, Description: repo.Description, @@ -113,7 +114,8 @@ func HandleFile(w http.ResponseWriter, r *http.Request) { return } - data.Lines = strings.Split(string(append(buf, buf2...)), "\n") + data.Body = string(append(buf, buf2...)) + data.Lines = strings.Split(data.Body, "\n") } }