File tree Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -44,32 +44,32 @@ const findLines = (el, lines) => {
4444const togglePod = ( e ) => {
4545 e . preventDefault ( ) ;
4646
47- const scrollTop = window . scrollTop ;
47+ const scrollTop = window . scrollY ;
4848
4949 let topLine ;
5050 let topOffset ;
51- for ( const line of document . querySelectorAll ( '.syntaxhighlighter .line' ) ) {
52- if ( line . classList . contains ( 'pod-line' ) ) {
53- continue ;
54- }
55- else if ( line . getClientRects ( ) . top < scrollTop ) {
51+ for ( const line of document . querySelectorAll ( '.syntaxhighlighter .container .line:not(.pod-line)' ) ) {
52+ const lineTop = line . getBoundingClientRect ( ) . top ;
53+ if ( lineTop < 0 ) {
5654 topLine = line ;
55+ topOffset = lineTop ;
56+ }
57+ else {
58+ break ;
5759 }
58- }
59- if ( topLine ) {
60- topOffset = line . getClientRects ( ) . top - scrollTop ;
6160 }
6261 for ( const toggle of document . querySelectorAll ( '.pod-toggle' ) ) {
6362 toggle . classList . toggle ( 'pod-hidden' ) ;
6463 }
6564 if ( topLine ) {
65+ const diff = topLine . getBoundingClientRect ( ) . top - topOffset ;
66+
6667 window . scrollTo ( {
67- top : line . getClientRects ( ) . top - topOffset ,
68+ top : scrollTop + diff ,
6869 left : 0 ,
6970 behavior : "instant"
7071 } ) ;
7172 }
72-
7373}
7474
7575const hashLines = / ^ # L ( \d + (?: - \d + ) ? (?: , \d + (?: - \d + ) ? ) * ) $ / ;
You can’t perform that action at this time.
0 commit comments