Skip to content

Commit db01bf6

Browse files
authored
Various code view improvements (#30014)
1. Restore missing styles for message close icon 2. Move `code-line-button` so that it does not go off-screen on small viewports 3. Make `code-line-button` look and behave like other buttons 4. Make `code-line-button` work in blame 5. Make the active selection span the whole line, not just the code part 6. Tweak colors, make dark theme code bg darker, make line numbers same color in diff and file view. 7. Move code background to parent, fixing border radius and other problems 8. Enable code wrap in blame 9. Improve blame responsiveness 10. Remove `--color-code-sidebar-bg` in blame, now it uses same background as code 11. Rename `--color-active-line` to `--color-highlight-bg` 12. Add `--color-highlight-bg` 13. Fix button group borders on hover and border-right on last button. <img width="1343" alt="Screenshot 2024-03-23 at 22 34 13" src="https://github.com/go-gitea/gitea/assets/115237/fcbb919f-5dc3-43f0-97f6-870d6f412554"> <img width="1334" alt="Screenshot 2024-03-23 at 22 34 26" src="https://github.com/go-gitea/gitea/assets/115237/ca44c3b7-4328-4645-ba49-b0dc6a5ac06d"> <img width="1338" alt="Screenshot 2024-03-23 at 22 34 57" src="https://github.com/go-gitea/gitea/assets/115237/00eb0b5a-1ec7-4669-a94a-4602b9d1c1ac"> <img width="1337" alt="Screenshot 2024-03-23 at 22 34 42" src="https://github.com/go-gitea/gitea/assets/115237/752edc4a-064f-413c-9dff-c086187fcd85"> Fixes: #18074
1 parent 9c6e6f4 commit db01bf6

File tree

12 files changed

+145
-103
lines changed

12 files changed

+145
-103
lines changed

routers/web/repo/blame.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func renderBlame(ctx *context.Context, blameParts []*git.BlamePart, commitNames
278278

279279
var avatar string
280280
if commit.User != nil {
281-
avatar = string(avatarUtils.Avatar(commit.User, 18, "gt-mr-3"))
281+
avatar = string(avatarUtils.Avatar(commit.User, 18))
282282
} else {
283283
avatar = string(avatarUtils.AvatarByEmail(commit.Author.Email, commit.Author.Name, 18, "gt-mr-3"))
284284
}

templates/devtest/gitea-ui.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/devtest.css?v={{AssetVersion}}">
33
<div class="page-content devtest ui container">
44
<div>
5+
<h1>Link</h1>
6+
<div>
7+
<a href="#">normal</a>
8+
<a class="muted" href="#">muted</a>
9+
<a class="suppressed" href="#">suppressed</a>
10+
<a class="silenced" href="#">silenced</a>
11+
</div>
512
<h1>Button</h1>
613
<div>
714
Style:

templates/repo/blame.tmpl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@
4141
{{$row.Avatar}}
4242
</div>
4343
<div class="blame-message">
44-
<a href="{{$row.CommitURL}}" title="{{$row.CommitMessage}}">
44+
<a class="suppressed tw-text-text" href="{{$row.CommitURL}}" title="{{$row.CommitMessage}}">
4545
{{$row.CommitMessage}}
4646
</a>
4747
</div>
48-
<div class="blame-time">
48+
<div class="blame-time not-mobile">
4949
{{$row.CommitSince}}
5050
</div>
5151
</div>
5252
</div>
5353
</td>
5454
<td class="lines-blame-btn">
5555
{{if $row.PreviousSha}}
56-
<a href="{{$row.PreviousShaURL}}" data-tooltip-content='{{ctx.Locale.Tr "repo.blame_prior"}}'>
56+
<a role="button" class="muted" href="{{$row.PreviousShaURL}}" data-tooltip-content='{{ctx.Locale.Tr "repo.blame_prior"}}'>
5757
{{svg "octicon-versions"}}
5858
</a>
5959
{{end}}
@@ -75,6 +75,12 @@
7575
{{end}}
7676
</tbody>
7777
</table>
78+
<div class="code-line-menu tippy-target">
79+
{{if $.Permission.CanRead $.UnitTypeIssues}}
80+
<a class="item ref-in-new-issue" role="menuitem" data-url-issue-new="{{.RepoLink}}/issues/new" data-url-param-body-link="{{.Repository.Link}}/src/commit/{{PathEscape .CommitID}}/{{PathEscapeSegments .TreePath}}{{if $.HasSourceRenderedToggle}}?display=source{{end}}" rel="nofollow noindex">{{ctx.Locale.Tr "repo.issues.context.reference_issue"}}</a>
81+
{{end}}
82+
<a class="item copy-line-permalink" role="menuitem" data-url="{{.Repository.Link}}/src/commit/{{PathEscape .CommitID}}/{{PathEscapeSegments .TreePath}}{{if $.HasSourceRenderedToggle}}?display=source{{end}}">{{ctx.Locale.Tr "repo.file_copy_permalink"}}</a>
83+
</div>
7884
</div>
7985
</div>
8086
</div>

web_src/css/base.css

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,14 @@ progress::-moz-progress-bar {
215215
a {
216216
color: var(--color-primary);
217217
cursor: pointer;
218-
text-decoration: none;
218+
text-decoration-line: none;
219219
text-decoration-skip-ink: all;
220220
}
221221

222+
a:hover {
223+
text-decoration-line: underline;
224+
}
225+
222226
/* a = always colored, underlined on hover */
223227
/* a.muted = colored on hover, underlined on hover */
224228
/* a.suppressed = never colored, underlined on hover */
@@ -245,15 +249,15 @@ a.suppressed:hover {
245249
}
246250

247251
a.silenced:hover {
248-
text-decoration: none;
252+
text-decoration-line: none;
249253
}
250254

251255
a.label,
252256
.ui.search .results a,
253257
.ui .menu a,
254258
.ui.cards a.card,
255259
.issue-keyword a {
256-
text-decoration: none !important;
260+
text-decoration-line: none !important;
257261
}
258262

259263
.ui.search > .results {
@@ -1418,18 +1422,15 @@ a.ui.active.label:hover {
14181422
}
14191423

14201424
.lines-blame-btn {
1421-
padding-left: 10px;
1422-
padding-right: 10px;
1423-
text-align: right !important;
1424-
background-color: var(--color-code-sidebar-bg);
1425-
width: 2%;
1425+
padding: 0 0 0 5px;
1426+
display: flex;
1427+
justify-content: center;
14261428
}
14271429

14281430
.lines-num {
1429-
padding-left: 10px;
1430-
padding-right: 10px;
1431+
padding: 0 8px;
14311432
text-align: right !important;
1432-
color: var(--color-text-light-1);
1433+
color: var(--color-text-light-2);
14331434
width: 1%;
14341435
font-family: var(--fonts-monospace);
14351436
}
@@ -1483,22 +1484,34 @@ a.ui.active.label:hover {
14831484
}
14841485

14851486
.lines-code {
1486-
background-color: var(--color-code-bg);
14871487
padding-left: 5px;
14881488
}
14891489

1490-
.lines-code.active,
1491-
.lines-code .active {
1492-
background: var(--color-active-line) !important;
1490+
.file-view tr.active {
1491+
color: inherit !important;
1492+
background: inherit !important;
14931493
}
14941494

1495-
.blame .lines-num {
1496-
padding: 0 !important;
1497-
background-color: var(--color-code-sidebar-bg);
1495+
.file-view tr.active .lines-num,
1496+
.file-view tr.active .lines-code {
1497+
background: var(--color-highlight-bg) !important;
14981498
}
14991499

1500-
.blame .lines-code {
1501-
padding: 0 !important;
1500+
.file-view tr.active:last-of-type .lines-code {
1501+
border-bottom-right-radius: var(--border-radius);
1502+
}
1503+
1504+
.file-view tr.active .lines-num {
1505+
position: relative;
1506+
}
1507+
1508+
.file-view tr.active .lines-num::before {
1509+
content: "";
1510+
position: absolute;
1511+
left: 0;
1512+
width: 2px;
1513+
height: 100%;
1514+
background: var(--color-highlight-fg);
15021515
}
15031516

15041517
.code-inner {
@@ -1509,24 +1522,21 @@ a.ui.active.label:hover {
15091522
}
15101523

15111524
.blame .code-inner {
1512-
white-space: pre;
1513-
word-break: normal;
1514-
word-wrap: normal; /* not using overflow-wrap because safari does not treat is an an alias */
1525+
white-space: pre-wrap;
1526+
overflow-wrap: anywhere;
15151527
}
15161528

15171529
.lines-commit {
15181530
vertical-align: top;
1519-
color: var(--color-text-light-2);
1531+
color: var(--color-text-light-1);
15201532
padding: 0 !important;
1521-
background: var(--color-code-sidebar-bg);
15221533
width: 1%;
15231534
}
15241535

15251536
.lines-commit .blame-info {
1526-
width: 350px;
1527-
max-width: 350px;
1537+
width: min(26vw, 300px);
15281538
display: block;
1529-
padding: 0 0 0 10px;
1539+
padding: 0 0 0 6px;
15301540
line-height: 20px;
15311541
box-sizing: content-box;
15321542
}
@@ -1548,11 +1558,10 @@ a.ui.active.label:hover {
15481558
flex-shrink: 0;
15491559
}
15501560

1551-
.lines-commit .ui.avatar {
1552-
height: 18px;
1553-
width: 18px;
1554-
display: block;
1555-
margin-top: 1px;
1561+
.blame-avatar {
1562+
display: flex;
1563+
align-items: center;
1564+
margin-right: 4px;
15561565
}
15571566

15581567
.top-line-blame {
@@ -1568,6 +1577,11 @@ a.ui.active.label:hover {
15681577
border-bottom: 1px solid var(--color-secondary);
15691578
}
15701579

1580+
.code-view {
1581+
background: var(--color-code-bg);
1582+
border-radius: var(--border-radius);
1583+
}
1584+
15711585
.code-view table {
15721586
width: 100%;
15731587
}

web_src/css/chroma/base.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.chroma {
2-
background-color: var(--color-code-bg);
3-
}
4-
51
/* LineTableTD */
62
.chroma .lntd {
73
vertical-align: top;

web_src/css/modules/button.css

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
.ui.button:hover {
1212
background: var(--color-hover);
1313
color: var(--color-text);
14+
border-color: var(--color-secondary-dark-2);
1415
}
1516

1617
.page-content .ui.button {
@@ -61,11 +62,17 @@ It needs some tricks to tweak the left/right borders with active state */
6162
border-right: none;
6263
}
6364

64-
.ui.buttons .button:first-child {
65+
.ui.buttons .button:hover + .button {
66+
border-left: 1px solid var(--color-secondary-dark-2);
67+
}
68+
69+
.ui.buttons .button:first-child,
70+
.ui.buttons .button.gt-hidden:first-child + .button {
6571
border-left: 1px solid var(--color-light-border);
6672
}
6773

68-
.ui.buttons .button:last-child {
74+
.ui.buttons .button:last-child,
75+
.ui.buttons .button:nth-last-child(2):has(+ .button.gt-hidden) {
6976
border-right: 1px solid var(--color-light-border);
7077
}
7178

@@ -105,6 +112,7 @@ It needs some tricks to tweak the left/right borders with active state */
105112
.ui.basic.button:hover {
106113
color: var(--color-text);
107114
background: var(--color-hover);
115+
border-color: var(--color-secondary-dark-2);
108116
}
109117

110118
.ui.basic.buttons .button:active,

web_src/css/modules/message.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,15 @@
100100
color: var(--color-warning-text);
101101
border-color: var(--color-warning-border);
102102
}
103+
104+
.ui.message > .close.icon {
105+
cursor: pointer;
106+
position: absolute;
107+
top: 9px;
108+
right: 9px;
109+
opacity: .7;
110+
}
111+
112+
.ui.message > .close.icon:hover {
113+
opacity: 1;
114+
}

web_src/css/repo.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,6 @@
16021602

16031603
.repository .diff-file-box .file-body.file-code .lines-num {
16041604
text-align: right;
1605-
color: var(--color-text-light);
16061605
width: 1%;
16071606
min-width: 50px;
16081607
}

web_src/css/repo/linebutton.css

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33
}
44

55
.code-line-button {
6-
background-color: var(--color-menu);
7-
color: var(--color-text-light);
86
border: 1px solid var(--color-secondary);
97
border-radius: var(--border-radius);
10-
padding: 1px 10px;
8+
padding: 1px 4px !important;
119
position: absolute;
1210
font-family: var(--fonts-regular);
1311
left: 0;
14-
transform: translateX(-50%);
12+
transform: translateX(calc(-50% + 6px));
1513
cursor: pointer;
1614
}
1715

1816
.code-line-button:hover {
19-
color: var(--color-primary);
17+
background: var(--color-secondary) !important;
2018
}

web_src/css/themes/theme-gitea-dark.css

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
--color-body: #1c1f25;
184184
--color-box-header: #1a1d1f;
185185
--color-box-body: #14171a;
186-
--color-box-body-highlight: #121517;
186+
--color-box-body-highlight: #1c2227;
187187
--color-text-dark: #f8f8f9;
188188
--color-text: #d1d5d8;
189189
--color-text-light: #bdc3c7;
@@ -207,11 +207,10 @@
207207
--color-markup-table-row: #e8e8ff06;
208208
--color-markup-code-block: #e8e8ff16;
209209
--color-button: #151a1e;
210-
--color-code-bg: #191d20;
211-
--color-code-sidebar-bg: #1b1f22;
210+
--color-code-bg: #14171a;
212211
--color-shadow: #00001758;
213-
--color-secondary-bg: #2f3135;
214-
--color-expand-button: #414348;
212+
--color-secondary-bg: #2f3138;
213+
--color-expand-button: #2b353e;
215214
--color-placeholder-text: var(--color-text-light-3);
216215
--color-editor-line-highlight: var(--color-primary-light-5);
217216
--color-project-board-bg: var(--color-secondary-light-2);
@@ -233,7 +232,8 @@
233232
--color-label-active-bg: #73828eff;
234233
--color-accent: var(--color-primary-light-1);
235234
--color-small-accent: var(--color-primary-light-5);
236-
--color-active-line: #534d1b;
235+
--color-highlight-fg: #87651e;
236+
--color-highlight-bg: #352c1c;
237237
--color-overlay-backdrop: #080808c0;
238238
accent-color: var(--color-accent);
239239
color-scheme: dark;

web_src/css/themes/theme-gitea-light.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
--color-body: #ffffff;
184184
--color-box-header: #f1f3f5;
185185
--color-box-body: #ffffff;
186-
--color-box-body-highlight: #f4faff;
186+
--color-box-body-highlight: #ecf5fd;
187187
--color-text-dark: #01050a;
188188
--color-text: #181c21;
189189
--color-text-light: #30363b;
@@ -208,10 +208,9 @@
208208
--color-markup-code-block: #00001710;
209209
--color-button: #f8f9fb;
210210
--color-code-bg: #fafdff;
211-
--color-code-sidebar-bg: #f2f5f8;
212211
--color-shadow: #00001726;
213212
--color-secondary-bg: #f2f5f8;
214-
--color-expand-button: #d8efff;
213+
--color-expand-button: #cfe8fa;
215214
--color-placeholder-text: var(--color-text-light-3);
216215
--color-editor-line-highlight: var(--color-primary-light-6);
217216
--color-project-board-bg: var(--color-secondary-light-4);
@@ -233,7 +232,8 @@
233232
--color-label-active-bg: #949da6ff;
234233
--color-accent: var(--color-primary-light-1);
235234
--color-small-accent: var(--color-primary-light-6);
236-
--color-active-line: #fffbdd;
235+
--color-highlight-fg: #eed200;
236+
--color-highlight-bg: #fffbdd;
237237
--color-overlay-backdrop: #080808c0;
238238
accent-color: var(--color-accent);
239239
color-scheme: light;

0 commit comments

Comments
 (0)