File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -202,8 +202,27 @@ document.addEventListener('keydown', (e) => {
202202 if ( e . key === 'Escape' ) closeSearch ( ) ;
203203} ) ;
204204
205+ // ---------- Sidebar scroll persistence ----------
206+ function restoreSidebarScroll ( ) {
207+ const sidebar = document . getElementById ( 'sidebar' ) ;
208+ if ( ! sidebar ) return ;
209+
210+ const saved = sessionStorage . getItem ( 'sidebar-scroll' ) ;
211+ if ( saved !== null ) {
212+ sidebar . scrollTop = parseInt ( saved , 10 ) ;
213+ }
214+
215+ // Before navigating away, save the current scroll position
216+ sidebar . querySelectorAll ( 'a' ) . forEach ( link => {
217+ link . addEventListener ( 'click' , ( ) => {
218+ sessionStorage . setItem ( 'sidebar-scroll' , sidebar . scrollTop ) ;
219+ } ) ;
220+ } ) ;
221+ }
222+
205223// ---------- Init ----------
206224initTheme ( ) ;
225+ restoreSidebarScroll ( ) ;
207226buildSearchIndex ( ) ;
208227buildTOC ( ) ;
209228addCopyButtons ( ) ;
You can’t perform that action at this time.
0 commit comments