mirror of
https://github.com/go-gitea/gitea.git
synced 2025-01-10 00:09:36 +01:00
Partially backport #33094 Fix the scroll bug in issue/pr view page. Fix a JS error when line number exceeds the max
This commit is contained in:
parent
e10d222434
commit
fd281518ae
@ -693,6 +693,7 @@ input:-webkit-autofill:active,
|
|||||||
|
|
||||||
.ui.dropdown .menu > .header {
|
.ui.dropdown .menu > .header {
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
|
text-transform: none; /* reset fomantic's "uppercase" */
|
||||||
}
|
}
|
||||||
|
|
||||||
.ui .text.left {
|
.ui .text.left {
|
||||||
|
@ -59,7 +59,7 @@ function selectRange($linesEls, $selectionEndEl, $selectionStartEls?) {
|
|||||||
copyPermalink.setAttribute('data-url', link);
|
copyPermalink.setAttribute('data-url', link);
|
||||||
};
|
};
|
||||||
|
|
||||||
if ($selectionStartEls) {
|
if ($selectionStartEls && $selectionStartEls[0]) {
|
||||||
let a = parseInt($selectionEndEl[0].getAttribute('rel').slice(1));
|
let a = parseInt($selectionEndEl[0].getAttribute('rel').slice(1));
|
||||||
let b = parseInt($selectionStartEls[0].getAttribute('rel').slice(1));
|
let b = parseInt($selectionStartEls[0].getAttribute('rel').slice(1));
|
||||||
let c;
|
let c;
|
||||||
|
@ -371,10 +371,6 @@ export async function handleReply(el) {
|
|||||||
|
|
||||||
export function initRepoPullRequestReview() {
|
export function initRepoPullRequestReview() {
|
||||||
if (window.location.hash && window.location.hash.startsWith('#issuecomment-')) {
|
if (window.location.hash && window.location.hash.startsWith('#issuecomment-')) {
|
||||||
// set scrollRestoration to 'manual' when there is a hash in url, so that the scroll position will not be remembered after refreshing
|
|
||||||
if (window.history.scrollRestoration !== 'manual') {
|
|
||||||
window.history.scrollRestoration = 'manual';
|
|
||||||
}
|
|
||||||
const commentDiv = document.querySelector(window.location.hash);
|
const commentDiv = document.querySelector(window.location.hash);
|
||||||
if (commentDiv) {
|
if (commentDiv) {
|
||||||
// get the name of the parent id
|
// get the name of the parent id
|
||||||
@ -382,14 +378,6 @@ export function initRepoPullRequestReview() {
|
|||||||
if (groupID && groupID.startsWith('code-comments-')) {
|
if (groupID && groupID.startsWith('code-comments-')) {
|
||||||
const id = groupID.slice(14);
|
const id = groupID.slice(14);
|
||||||
const ancestorDiffBox = commentDiv.closest('.diff-file-box');
|
const ancestorDiffBox = commentDiv.closest('.diff-file-box');
|
||||||
// on pages like conversation, there is no diff header
|
|
||||||
const diffHeader = ancestorDiffBox?.querySelector('.diff-file-header');
|
|
||||||
|
|
||||||
// offset is for scrolling
|
|
||||||
let offset = 30;
|
|
||||||
if (diffHeader) {
|
|
||||||
offset += $('.diff-detail-box').outerHeight() + $(diffHeader).outerHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
hideElem(`#show-outdated-${id}`);
|
hideElem(`#show-outdated-${id}`);
|
||||||
showElem(`#code-comments-${id}, #code-preview-${id}, #hide-outdated-${id}`);
|
showElem(`#code-comments-${id}, #code-preview-${id}, #hide-outdated-${id}`);
|
||||||
@ -397,12 +385,12 @@ export function initRepoPullRequestReview() {
|
|||||||
if (ancestorDiffBox?.getAttribute('data-folded') === 'true') {
|
if (ancestorDiffBox?.getAttribute('data-folded') === 'true') {
|
||||||
setFileFolding(ancestorDiffBox, ancestorDiffBox.querySelector('.fold-file'), false);
|
setFileFolding(ancestorDiffBox, ancestorDiffBox.querySelector('.fold-file'), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.scrollTo({
|
|
||||||
top: $(commentDiv).offset().top - offset,
|
|
||||||
behavior: 'instant',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set scrollRestoration to 'manual' when there is a hash in url, so that the scroll position will not be remembered after refreshing
|
||||||
|
if (window.history.scrollRestoration !== 'manual') window.history.scrollRestoration = 'manual';
|
||||||
|
// wait for a while because some elements (eg: image, editor, etc.) may change the viewport's height.
|
||||||
|
setTimeout(() => commentDiv.scrollIntoView({block: 'start'}), 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user