From d149093ce3c32503b95c66208de6cb5861e4e666 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 4 Apr 2023 19:05:07 +0800 Subject: [PATCH] Fix code view (diff) broken layout (#23096) 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) --- 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 f4f7732c50..caa428dc28 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 c4b5ad042c..4fa81f4e62 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 e0ec85f9a6..ba4ad5b513 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 7a1e3e9421..2ad3458501 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 d1af6b063d..90faf3cf66 100644 --- a/web_src/css/repository.css +++ b/web_src/css/repository.css @@ -1806,8 +1806,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 724e68ebb7..07f9a9d2ad 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 03c9977f49..f2a6f5815b 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -504,18 +504,9 @@ export function initRepoPullRequestReview() { ntr = $(` ${isSplit ? ` - - - - - - ` : ` - - - `} `);