@@ -371,38 +371,26 @@ export async function handleReply(el) {
371
371
372
372
export function initRepoPullRequestReview ( ) {
373
373
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
- }
378
374
const commentDiv = document . querySelector ( window . location . hash ) ;
379
375
if ( commentDiv ) {
380
376
// get the name of the parent id
381
377
const groupID = commentDiv . closest ( 'div[id^="code-comments-"]' ) ?. getAttribute ( 'id' ) ;
382
378
if ( groupID && groupID . startsWith ( 'code-comments-' ) ) {
383
379
const id = groupID . slice ( 14 ) ;
384
380
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
- }
393
381
394
382
hideElem ( `#show-outdated-${ id } ` ) ;
395
383
showElem ( `#code-comments-${ id } , #code-preview-${ id } , #hide-outdated-${ id } ` ) ;
396
384
// if the comment box is folded, expand it
397
385
if ( ancestorDiffBox ?. getAttribute ( 'data-folded' ) === 'true' ) {
398
386
setFileFolding ( ancestorDiffBox , ancestorDiffBox . querySelector ( '.fold-file' ) , false ) ;
399
387
}
400
-
401
- window . scrollTo ( {
402
- top : $ ( commentDiv ) . offset ( ) . top - offset ,
403
- behavior : 'instant' ,
404
- } ) ;
405
388
}
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 ) ;
406
394
}
407
395
}
408
396
0 commit comments