@@ -50,6 +50,7 @@ export const DeclarationsSidebar = ({ onNavigate }: { onNavigate?: () => void })
5050 const parentRef = useRef < HTMLDivElement > ( null ) ;
5151 const wrapperRef = useRef < HTMLDivElement > ( null ) ;
5252 const activeStickyIndexRef = useRef ( 0 ) ;
53+ const navigatedFromSidebarRef = useRef ( false ) ;
5354
5455 const groups = useMemo ( ( ) => {
5556 let filtered = declarations ;
@@ -138,9 +139,13 @@ export const DeclarationsSidebar = ({ onNavigate }: { onNavigate?: () => void })
138139 } ) ;
139140 } , [ activeModule , scope ] ) ;
140141
141- // Scroll to active item on navigation
142+ // Scroll to active item on navigation (skip if the click came from the sidebar)
142143 useEffect ( ( ) => {
143144 if ( ! scope || ! activeModule ) return ;
145+ if ( navigatedFromSidebarRef . current ) {
146+ navigatedFromSidebarRef . current = false ;
147+ return ;
148+ }
144149 const idx = rows . findIndex (
145150 ( r ) =>
146151 r . type === "item" && r . declaration . name === scope && r . declaration . module === activeModule ,
@@ -154,6 +159,11 @@ export const DeclarationsSidebar = ({ onNavigate }: { onNavigate?: () => void })
154159 }
155160 } , [ activeModule , scope , rows , virtualizer ] ) ;
156161
162+ const handleSidebarNavigate = useCallback ( ( ) => {
163+ navigatedFromSidebarRef . current = true ;
164+ onNavigate ?.( ) ;
165+ } , [ onNavigate ] ) ;
166+
157167 const { game } = useContext ( DeclarationsContext ) ;
158168
159169 return (
@@ -209,7 +219,10 @@ export const DeclarationsSidebar = ({ onNavigate }: { onNavigate?: () => void })
209219 </ SidebarGroupHeader >
210220 </ div >
211221 ) : (
212- < DeclarationSidebarElement declaration = { row . declaration } onClick = { onNavigate } />
222+ < DeclarationSidebarElement
223+ declaration = { row . declaration }
224+ onClick = { handleSidebarNavigate }
225+ />
213226 ) }
214227 </ div >
215228 ) ;
0 commit comments