@@ -6,6 +6,7 @@ import {initEasyMDEImagePaste} from './comp/ImagePaste.js';
6
6
import { initCompMarkupContentPreviewTab } from './comp/MarkupContentPreview.js' ;
7
7
import { initTooltip , showTemporaryTooltip , createTippy } from '../modules/tippy.js' ;
8
8
import { hideElem , showElem , toggleElem } from '../utils/dom.js' ;
9
+ import { setFileFolding } from './file-fold.js' ;
9
10
10
11
const { appSubUrl, csrfToken} = window . config ;
11
12
@@ -436,17 +437,36 @@ export async function handleReply($el) {
436
437
437
438
export function initRepoPullRequestReview ( ) {
438
439
if ( window . location . hash && window . location . hash . startsWith ( '#issuecomment-' ) ) {
440
+ // set scrollRestoration to 'manual' when there is a hash in url, so that the scroll position will not be remembered after refreshing
441
+ if ( window . history . scrollRestoration !== 'manual' ) {
442
+ window . history . scrollRestoration = 'manual' ;
443
+ }
439
444
const commentDiv = $ ( window . location . hash ) ;
440
445
if ( commentDiv ) {
441
446
// get the name of the parent id
442
447
const groupID = commentDiv . closest ( 'div[id^="code-comments-"]' ) . attr ( 'id' ) ;
443
448
if ( groupID && groupID . startsWith ( 'code-comments-' ) ) {
444
449
const id = groupID . slice ( 14 ) ;
450
+ const ancestorDiffBox = commentDiv . closest ( '.diff-file-box' ) ;
451
+ // on pages like conversation, there is no diff header
452
+ const diffHeader = ancestorDiffBox . find ( '.diff-file-header' ) ;
453
+ // offset is for scrolling
454
+ let offset = 30 ;
455
+ if ( diffHeader [ 0 ] ) {
456
+ offset += $ ( '.diff-detail-box' ) . outerHeight ( ) + diffHeader . outerHeight ( ) ;
457
+ }
445
458
$ ( `#show-outdated-${ id } ` ) . addClass ( 'gt-hidden' ) ;
446
459
$ ( `#code-comments-${ id } ` ) . removeClass ( 'gt-hidden' ) ;
447
460
$ ( `#code-preview-${ id } ` ) . removeClass ( 'gt-hidden' ) ;
448
461
$ ( `#hide-outdated-${ id } ` ) . removeClass ( 'gt-hidden' ) ;
449
- commentDiv [ 0 ] . scrollIntoView ( ) ;
462
+ // if the comment box is folded, expand it
463
+ if ( ancestorDiffBox . attr ( 'data-folded' ) && ancestorDiffBox . attr ( 'data-folded' ) === 'true' ) {
464
+ setFileFolding ( ancestorDiffBox [ 0 ] , ancestorDiffBox . find ( '.fold-file' ) [ 0 ] , false ) ;
465
+ }
466
+ window . scrollTo ( {
467
+ top : commentDiv . offset ( ) . top - offset ,
468
+ behavior : 'instant'
469
+ } ) ;
450
470
}
451
471
}
452
472
}
0 commit comments