Skip to content

Commit df74ee0

Browse files
GiteaBotjpraet
andauthored
Scroll collapsed file into view (#23702) (#23929)
Backport #23702 by @jpraet Fixes #23701, #23515. Alternate approach to #23604 using CSS scroll-margin-top, which is also taken into account for direct links to files in a diff: * On the PR diff, this currently shows the previous file first: https://try.gitea.io/jpraet/test/pulls/13/files#diff-b94d08b409f9d05fb65b6cccaf7b3e4ecc7cc333 * On the commit diff, the first line of the linked file is currently under the sticky header: https://try.gitea.io/jpraet/test/commit/1a19e6b14e31d295b7372f3346580c3e85690ff5#diff-b94d08b409f9d05fb65b6cccaf7b3e4ecc7cc333 Co-authored-by: Jimmy Praet <[email protected]>
1 parent 8d88f14 commit df74ee0

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

web_src/css/repository.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,13 @@
18621862
.diff-file-box {
18631863
border: 1px solid transparent;
18641864
border-radius: var(--border-radius);
1865+
scroll-margin-top: 47px; /* match .repository .diff-detail-box */
1866+
}
1867+
1868+
@media (max-width: 991px) {
1869+
.diff-file-box {
1870+
scroll-margin-top: 77px; /* match .repository .diff-detail-box */
1871+
}
18651872
}
18661873

18671874
/* TODO: this can potentially be made "global" by removing the class prefix */

web_src/css/review.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,12 @@ a.blob-excerpt:hover {
242242
display: none;
243243
}
244244

245-
.pull.files.diff [id] {
245+
.pull.files.diff .comment {
246246
scroll-margin-top: 99px;
247247
}
248248

249249
@media (max-width: 991px) {
250-
.pull.files.diff [id] {
250+
.pull.files.diff .comment {
251251
scroll-margin-top: 130px;
252252
}
253253
}

web_src/js/features/file-fold.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import {svg} from '../svg.js';
88
export function setFileFolding(fileContentBox, foldArrow, newFold) {
99
foldArrow.innerHTML = svg(`octicon-chevron-${newFold ? 'right' : 'down'}`, 18);
1010
fileContentBox.setAttribute('data-folded', newFold);
11+
if (newFold && fileContentBox.getBoundingClientRect().top < 0) {
12+
fileContentBox.scrollIntoView();
13+
}
1114
}
1215

1316
// Like `setFileFolding`, except that it automatically inverts the current file folding state.

0 commit comments

Comments
 (0)