@@ -371,38 +371,26 @@ export async function handleReply(el) {
371371
372372export 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