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) => {
44
44
const togglePod = ( e ) => {
45
45
e . preventDefault ( ) ;
46
46
47
- const scrollTop = window . scrollTop ;
47
+ const scrollTop = window . scrollY ;
48
48
49
49
let topLine ;
50
50
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 ) {
56
54
topLine = line ;
55
+ topOffset = lineTop ;
56
+ }
57
+ else {
58
+ break ;
57
59
}
58
- }
59
- if ( topLine ) {
60
- topOffset = line . getClientRects ( ) . top - scrollTop ;
61
60
}
62
61
for ( const toggle of document . querySelectorAll ( '.pod-toggle' ) ) {
63
62
toggle . classList . toggle ( 'pod-hidden' ) ;
64
63
}
65
64
if ( topLine ) {
65
+ const diff = topLine . getBoundingClientRect ( ) . top - topOffset ;
66
+
66
67
window . scrollTo ( {
67
- top : line . getClientRects ( ) . top - topOffset ,
68
+ top : scrollTop + diff ,
68
69
left : 0 ,
69
70
behavior : "instant"
70
71
} ) ;
71
72
}
72
-
73
73
}
74
74
75
75
const hashLines = / ^ # L ( \d + (?: - \d + ) ? (?: , \d + (?: - \d + ) ? ) * ) $ / ;
You can’t perform that action at this time.
0 commit comments