@@ -132,8 +132,9 @@ const handleSeeMore = () => {
132132 const pre = line . closest ( 'pre' ) ;
133133 const initialHeight = pre . offsetHeight ;
134134 let animationSpeed = 0 ;
135+ const transition = line . classList . contains ( 'cbp-see-more-transition' ) ;
135136
136- if ( line . classList . contains ( 'cbp-see-more- transition' ) ) {
137+ if ( transition ) {
137138 const lineCount = pre . querySelectorAll ( 'code > *' ) . length ;
138139 const linesBeforeCurrent = Array . from (
139140 line . closest ( 'code' ) . children ,
@@ -169,17 +170,29 @@ const handleSeeMore = () => {
169170
170171 const handle = ( event ) => {
171172 event . preventDefault ( ) ;
172- button . classList . remove ( 'cbp-see-more-simple-btn-hover' ) ;
173- pre . style . maxHeight = initialHeight + 'px' ;
173+ // disable scrolling
174+ pre . style . setProperty ( 'overflow' , 'hidden' , 'important' ) ;
175+ setTimeout ( ( ) => {
176+ pre . style . overflow = 'auto' ;
177+ } , animationSpeed * 1000 ) ;
178+
179+ pre . style . maxHeight = `${ initialHeight } px` ;
174180 // If there is data-see-more-collapse-string then we toggle
175181 if ( ! buttonContainer . dataset ?. seeMoreCollapseString ) {
176182 buttonContainer . remove ( ) ;
177183 return ;
178184 }
185+ // We're letting them collapse it
179186 if ( button . getAttribute ( 'aria-expanded' ) === 'true' ) {
180187 button . setAttribute ( 'aria-expanded' , 'false' ) ;
181188 button . innerText = buttonContainer . dataset . seeMoreString ;
182- pre . style . maxHeight = `${ line . offsetTop + lineHeight } px` ;
189+ pre . style . maxHeight = `${ line . offsetTop + lineHeight - headerHeight } px` ;
190+
191+ // Move the scroll so the button is in center view
192+ line . scrollIntoView ( {
193+ behavior : transition ? 'smooth' : 'auto' ,
194+ block : 'center' ,
195+ } ) ;
183196 return ;
184197 }
185198 button . setAttribute ( 'aria-expanded' , 'true' ) ;
0 commit comments