From 7c180ff8eb733e13b1e8449f911a3547a1c7ce8c Mon Sep 17 00:00:00 2001 From: Giteabot Date: Tue, 4 Apr 2023 10:02:29 -0400 Subject: [PATCH] Fix code view (diff) broken layout (#23096) (#23918) Backport #23096 by @wxiaoguang Close #22911 I think it's ready for review now, feel free to test it, welcome to help to improve. ### Before ![image](https://user-images.githubusercontent.com/2114189/220958734-06871615-b498-4143-8449-3d443f08ffaa.png) ### After ![image](https://user-images.githubusercontent.com/2114189/220958621-0dce2728-57b8-4a1f-ac5d-48c7c2d42f5c.png) Co-authored-by: wxiaoguang --- templates/repo/diff/blob_excerpt.tmpl | 6 ++--- templates/repo/diff/section_split.tmpl | 30 +++++++++++------------- templates/repo/diff/section_unified.tmpl | 8 ++++++- templates/repo/settings/lfs_file.tmpl | 2 +- web_src/css/repository.css | 10 ++++++-- web_src/css/review.css | 6 ----- web_src/js/features/repo-issue.js | 9 ------- 7 files changed, 33 insertions(+), 38 deletions(-) diff --git a/templates/repo/diff/blob_excerpt.tmpl b/templates/repo/diff/blob_excerpt.tmpl index f4f7732c5..caa428dc2 100644 --- a/templates/repo/diff/blob_excerpt.tmpl +++ b/templates/repo/diff/blob_excerpt.tmpl @@ -19,14 +19,14 @@ {{end}} - {{$inlineDiff := $.section.GetComputedInlineDiffFor $line $.locale}}{{/* + {{$inlineDiff := $.section.GetComputedInlineDiffFor $line $.locale}}{{/* */}}{{template "repo/diff/section_code" dict "diff" $inlineDiff "locale" $.locale}} {{else}} {{$inlineDiff := $.section.GetComputedInlineDiffFor $line $.locale}} {{if and $line.LeftIdx $inlineDiff.EscapeStatus.Escaped}}{{end}} {{if $line.LeftIdx}}{{end}} - {{/* + {{/* */}}{{if $line.LeftIdx}}{{template "repo/diff/section_code" dict "diff" $inlineDiff "locale" $.locale}}{{else}}{{/* */}}{{/* */}}{{end}}{{/* @@ -34,7 +34,7 @@ {{if and $line.RightIdx $inlineDiff.EscapeStatus.Escaped}}{{end}} {{if $line.RightIdx}}{{end}} - {{/* + {{/* */}}{{if $line.RightIdx}}{{template "repo/diff/section_code" dict "diff" $inlineDiff "locale" $.locale}}{{else}}{{/* */}}{{/* */}}{{end}}{{/* diff --git a/templates/repo/diff/section_split.tmpl b/templates/repo/diff/section_split.tmpl index c4b5ad042..4fa81f4e6 100644 --- a/templates/repo/diff/section_split.tmpl +++ b/templates/repo/diff/section_split.tmpl @@ -1,4 +1,14 @@ {{$file := .file}} + + + + + + + + + + {{range $j, $section := $file.Sections}} {{range $k, $line := $section.Lines}} {{$hasmatch := ne $line.Match -1}} @@ -33,7 +43,7 @@ {{if $line.LeftIdx}}{{if $leftDiff.EscapeStatus.Escaped}}{{end}}{{end}} - {{/* + {{/* */}}{{if and $.root.SignedUserID $.root.PageIsPullFiles}}{{/* */}}{{/* */}}{{svg "octicon-plus"}}{{/* @@ -48,7 +58,7 @@ {{if $match.RightIdx}}{{if $rightDiff.EscapeStatus.Escaped}}{{end}}{{end}} {{if $match.RightIdx}}{{end}} - {{/* + {{/* */}}{{if and $.root.SignedUserID $.root.PageIsPullFiles}}{{/* */}}{{/* */}}{{svg "octicon-plus"}}{{/* @@ -65,7 +75,7 @@ {{if $line.LeftIdx}}{{if $inlineDiff.EscapeStatus.Escaped}}{{end}}{{end}} {{if $line.LeftIdx}}{{end}} - {{/* + {{/* */}}{{if and $.root.SignedUserID $.root.PageIsPullFiles (not (eq .GetType 2))}}{{/* */}}{{/* */}}{{svg "octicon-plus"}}{{/* @@ -80,7 +90,7 @@ {{if $line.RightIdx}}{{if $inlineDiff.EscapeStatus.Escaped}}{{end}}{{end}} {{if $line.RightIdx}}{{end}} - {{/* + {{/* */}}{{if and $.root.SignedUserID $.root.PageIsPullFiles (not (eq .GetType 3))}}{{/* */}}{{/* */}}{{svg "octicon-plus"}}{{/* @@ -98,9 +108,6 @@ {{$match := index $section.Lines $line.Match}} {{if or (gt (len $line.Comments) 0) (gt (len $match.Comments) 0)}} - - - {{if gt (len $line.Comments) 0}} {{if eq $line.GetCommentSide "previous"}} @@ -113,9 +120,6 @@ {{end}} {{end}} - - - {{if eq $line.GetCommentSide "proposed"}} {{template "repo/diff/conversation" mergeinto $.root "comments" $line.Comments}} @@ -130,9 +134,6 @@ {{end}} {{else if gt (len $line.Comments) 0}} - - - {{if gt (len $line.Comments) 0}} {{if eq $line.GetCommentSide "previous"}} @@ -140,9 +141,6 @@ {{end}} {{end}} - - - {{if eq $line.GetCommentSide "proposed"}} {{template "repo/diff/conversation" mergeinto $.root "comments" $line.Comments}} diff --git a/templates/repo/diff/section_unified.tmpl b/templates/repo/diff/section_unified.tmpl index e0ec85f9a..ba4ad5b51 100644 --- a/templates/repo/diff/section_unified.tmpl +++ b/templates/repo/diff/section_unified.tmpl @@ -1,4 +1,11 @@ {{$file := .file}} + + + + + + + {{range $j, $section := $file.Sections}} {{range $k, $line := $section.Lines}} @@ -49,7 +56,6 @@ {{if gt (len $line.Comments) 0}} - {{template "repo/diff/conversation" mergeinto $.root "comments" $line.Comments}} diff --git a/templates/repo/settings/lfs_file.tmpl b/templates/repo/settings/lfs_file.tmpl index 7a1e3e942..2ad345850 100644 --- a/templates/repo/settings/lfs_file.tmpl +++ b/templates/repo/settings/lfs_file.tmpl @@ -48,7 +48,7 @@ {{.locale.Tr "repo.file_too_large"}} {{else}} {{.LineNums}} -
    {{.FileContent}}
+
    {{.FileContent}}
{{end}} diff --git a/web_src/css/repository.css b/web_src/css/repository.css index e84e80b67..4bb49dc43 100644 --- a/web_src/css/repository.css +++ b/web_src/css/repository.css @@ -1801,8 +1801,14 @@ padding: 0 !important; } -.repository .diff-file-box .code-diff tbody tr td.halfwidth { - width: 49%; /* halfwidth is used in split view - and in that case, 1% of each */ +.repository .diff-file-box .code-diff table { + table-layout: fixed; +} + +.repository .diff-file-box .code-diff tbody tr td.lines-num, +.repository .diff-file-box .code-diff tbody tr td.lines-escape, +.repository .diff-file-box .code-diff tbody tr td.lines-type-marker { + white-space: nowrap; } .repository .diff-file-box .code-diff tbody tr td.center { diff --git a/web_src/css/review.css b/web_src/css/review.css index 05456c381..7e628a9df 100644 --- a/web_src/css/review.css +++ b/web_src/css/review.css @@ -53,12 +53,6 @@ margin-bottom: 0.5em; } -.add-comment .lines-num, -.add-comment .lines-escape, -.add-comment .lines-type-marker { - display: none; -} - .show-outdated:hover, .hide-outdated:hover { text-decoration: underline; diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index 7265873b1..8305038ea 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -548,18 +548,9 @@ export function initRepoPullRequestReview() { ntr = $(` ${isSplit ? ` - - - - - - ` : ` - - - `} `);