From 7034efc7dc0e355c63b11f0f633216d489d254be Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 29 May 2024 08:08:45 +0200 Subject: [PATCH] Use vertical layout for multiple code expander buttons (#31122) Fixes: https://github.com/go-gitea/gitea/issues/31068 - Now it only does a single call to `GetExpandDirection` per line instead of multiples. - Exposed `data-expand-direction` to frontend so it can correctly size the buttons (it's a pain to do in tables). Screenshot 2024-05-27 at 20 44 56 Screenshot 2024-05-27 at 20 44 51 Screenshot 2024-05-27 at 20 44 46 Screenshot 2024-05-27 at 20 44 33 Screenshot 2024-05-27 at 20 44 26 Screenshot 2024-05-27 at 20 44 20 Would backport as trivial enhancement. --- templates/repo/diff/blob_excerpt.tmpl | 18 ++++++++++-------- templates/repo/diff/section_split.tmpl | 9 +++++---- templates/repo/diff/section_unified.tmpl | 9 +++++---- web_src/css/review.css | 5 +++++ 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/templates/repo/diff/blob_excerpt.tmpl b/templates/repo/diff/blob_excerpt.tmpl index a80abe263f..2874ac6a55 100644 --- a/templates/repo/diff/blob_excerpt.tmpl +++ b/templates/repo/diff/blob_excerpt.tmpl @@ -2,19 +2,20 @@ {{range $k, $line := $.section.Lines}} {{if eq .GetType 4}} + {{$expandDirection := $line.GetExpandDirection}} -
- {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5)}} +
+ {{if or (eq $expandDirection 3) (eq $expandDirection 5)}} {{end}} - {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4)}} + {{if or (eq $expandDirection 3) (eq $expandDirection 4)}} {{end}} - {{if eq $line.GetExpandDirection 2}} + {{if eq $expandDirection 2}} @@ -48,19 +49,20 @@ {{range $k, $line := $.section.Lines}} {{if eq .GetType 4}} + {{$expandDirection := $line.GetExpandDirection}} -
- {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5)}} +
+ {{if or (eq $expandDirection 3) (eq $expandDirection 5)}} {{end}} - {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4)}} + {{if or (eq $expandDirection 3) (eq $expandDirection 4)}} {{end}} - {{if eq $line.GetExpandDirection 2}} + {{if eq $expandDirection 2}} diff --git a/templates/repo/diff/section_split.tmpl b/templates/repo/diff/section_split.tmpl index 349f0c3dfc..37b42bcb37 100644 --- a/templates/repo/diff/section_split.tmpl +++ b/templates/repo/diff/section_split.tmpl @@ -16,19 +16,20 @@ {{if or (ne .GetType 2) (not $hasmatch)}} {{if eq .GetType 4}} + {{$expandDirection := $line.GetExpandDirection}} -
- {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5)}} +
+ {{if or (eq $expandDirection 3) (eq $expandDirection 5)}} {{end}} - {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4)}} + {{if or (eq $expandDirection 3) (eq $expandDirection 4)}} {{end}} - {{if eq $line.GetExpandDirection 2}} + {{if eq $expandDirection 2}} diff --git a/templates/repo/diff/section_unified.tmpl b/templates/repo/diff/section_unified.tmpl index ec59f4d42e..708b333291 100644 --- a/templates/repo/diff/section_unified.tmpl +++ b/templates/repo/diff/section_unified.tmpl @@ -12,19 +12,20 @@ {{if eq .GetType 4}} {{if $.root.AfterCommitID}} + {{$expandDirection := $line.GetExpandDirection}} -
- {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5)}} +
+ {{if or (eq $expandDirection 3) (eq $expandDirection 5)}} {{end}} - {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4)}} + {{if or (eq $expandDirection 3) (eq $expandDirection 4)}} {{end}} - {{if eq $line.GetExpandDirection 2}} + {{if eq $expandDirection 2}} diff --git a/web_src/css/review.css b/web_src/css/review.css index 6337748939..0d69e36681 100644 --- a/web_src/css/review.css +++ b/web_src/css/review.css @@ -164,6 +164,11 @@ flex: 1; } +/* expand direction 3 is both ways with two buttons */ +.code-expander-buttons[data-expand-direction="3"] .code-expander-button { + height: 18px; +} + .code-expander-button:hover { background: var(--color-primary); color: var(--color-primary-contrast);