Skip to content

Commit fd28151

Browse files
authored
Fix line-number and scroll bugs (#33094) (#33095)
Partially backport #33094 Fix the scroll bug in issue/pr view page. Fix a JS error when line number exceeds the max
1 parent e10d222 commit fd28151

File tree

3 files changed

+7
-18
lines changed

3 files changed

+7
-18
lines changed

Diff for: web_src/css/base.css

+1
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@ input:-webkit-autofill:active,
693693

694694
.ui.dropdown .menu > .header {
695695
font-size: 0.8em;
696+
text-transform: none; /* reset fomantic's "uppercase" */
696697
}
697698

698699
.ui .text.left {

Diff for: web_src/js/features/repo-code.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function selectRange($linesEls, $selectionEndEl, $selectionStartEls?) {
5959
copyPermalink.setAttribute('data-url', link);
6060
};
6161

62-
if ($selectionStartEls) {
62+
if ($selectionStartEls && $selectionStartEls[0]) {
6363
let a = parseInt($selectionEndEl[0].getAttribute('rel').slice(1));
6464
let b = parseInt($selectionStartEls[0].getAttribute('rel').slice(1));
6565
let c;

Diff for: web_src/js/features/repo-issue.ts

+5-17
Original file line numberDiff line numberDiff line change
@@ -371,38 +371,26 @@ export async function handleReply(el) {
371371

372372
export function initRepoPullRequestReview() {
373373
if (window.location.hash && window.location.hash.startsWith('#issuecomment-')) {
374-
// set scrollRestoration to 'manual' when there is a hash in url, so that the scroll position will not be remembered after refreshing
375-
if (window.history.scrollRestoration !== 'manual') {
376-
window.history.scrollRestoration = 'manual';
377-
}
378374
const commentDiv = document.querySelector(window.location.hash);
379375
if (commentDiv) {
380376
// get the name of the parent id
381377
const groupID = commentDiv.closest('div[id^="code-comments-"]')?.getAttribute('id');
382378
if (groupID && groupID.startsWith('code-comments-')) {
383379
const id = groupID.slice(14);
384380
const ancestorDiffBox = commentDiv.closest('.diff-file-box');
385-
// on pages like conversation, there is no diff header
386-
const diffHeader = ancestorDiffBox?.querySelector('.diff-file-header');
387-
388-
// offset is for scrolling
389-
let offset = 30;
390-
if (diffHeader) {
391-
offset += $('.diff-detail-box').outerHeight() + $(diffHeader).outerHeight();
392-
}
393381

394382
hideElem(`#show-outdated-${id}`);
395383
showElem(`#code-comments-${id}, #code-preview-${id}, #hide-outdated-${id}`);
396384
// if the comment box is folded, expand it
397385
if (ancestorDiffBox?.getAttribute('data-folded') === 'true') {
398386
setFileFolding(ancestorDiffBox, ancestorDiffBox.querySelector('.fold-file'), false);
399387
}
400-
401-
window.scrollTo({
402-
top: $(commentDiv).offset().top - offset,
403-
behavior: 'instant',
404-
});
405388
}
389+
390+
// set scrollRestoration to 'manual' when there is a hash in url, so that the scroll position will not be remembered after refreshing
391+
if (window.history.scrollRestoration !== 'manual') window.history.scrollRestoration = 'manual';
392+
// wait for a while because some elements (eg: image, editor, etc.) may change the viewport's height.
393+
setTimeout(() => commentDiv.scrollIntoView({block: 'start'}), 100);
406394
}
407395
}
408396

0 commit comments

Comments
 (0)