66    markRaw , 
77    watch , 
88    computed , 
9+     watchEffect 
910}  from  "vue" ; 
1011import  {  useWindowSize  }  from  "vue-window-size" ; 
1112
@@ -124,6 +125,8 @@ const app = createApp({
124125        const  snackbarMessage  =  ref ( ) ; 
125126        const  snackbarColor  =  ref ( ) ; 
126127
128+         const  searchQuery  =  ref ( '' ) ; 
129+ 
127130        function  copyToClipboard ( copyText )  { 
128131            navigator . clipboard 
129132                . writeText ( window . location . origin  +  "/"  +  copyText ) 
@@ -188,6 +191,7 @@ const app = createApp({
188191
189192        const  sectionTitle  =  ref ( currentPage ?. [ 0 ] ?. title  ||  "Essential C#" ) ; 
190193        const  expandedTocs  =  reactive ( new  Set ( ) ) ; 
194+ 
191195        for  ( const  item  of  currentPage )  { 
192196            expandedTocs . add ( item . key ) ; 
193197        } 
@@ -235,11 +239,10 @@ const app = createApp({
235239        } ) ; 
236240
237241        const  enableTocFilter  =  ref ( 'none' ) ; 
238-         const  searchQuery  =  ref ( '' ) ; 
239242
240243        const  filteredTocData  =  computed ( ( )  =>  { 
241-             expandedTocs . clear ( ) ; 
242244            if  ( ! searchQuery . value )  { 
245+                 expandedTocs . clear ( ) ; 
243246                return  tocData ; 
244247            } 
245248            const  query  =  normalizeString ( searchQuery . value ) ; 
@@ -252,12 +255,20 @@ const app = createApp({
252255                const  childMatches  =  item . items . some ( child  =>  filterItem ( child ,  query ) ) ; 
253256                matches  =  matches  ||  childMatches ; 
254257            } 
255-             if  ( matches )  { 
256-                 expandedTocs . add ( item . key ) ;  // Add matching item to expandedTocs 
257-             } 
258258            return  matches ; 
259259        } 
260260
261+         watchEffect ( ( )  =>  { 
262+             expandedTocs . clear ( ) ; 
263+             const  query  =  normalizeString ( searchQuery . value ) ; 
264+             tocData . forEach ( item  =>  { 
265+                 if  ( filterItem ( item ,  query ) )  { 
266+                     expandedTocs . add ( item . key ) ; 
267+                     console . log ( "Added " ,  item . key ) ; 
268+                 } 
269+             } ) ; 
270+         } ) ; 
271+ 
261272        function  normalizeString ( str )  { 
262273            return  str . replace ( / [ ^ \w \s ] | _ / g,  "" ) . replace ( / \s + / g,  " " ) . toLowerCase ( ) ; 
263274        } 
0 commit comments