File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed 
EssentialCSharp.Web/wwwroot/js Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change 66    markRaw , 
77    watch , 
88    computed , 
9-     watchEffect 
109}  from  "vue" ; 
1110import  {  useWindowSize  }  from  "vue-window-size" ; 
1211
@@ -240,7 +239,6 @@ const app = createApp({
240239
241240        const  filteredTocData  =  computed ( ( )  =>  { 
242241            if  ( ! searchQuery . value )  { 
243-                 expandedTocs . clear ( ) ; 
244242                return  tocData ; 
245243            } 
246244            const  query  =  normalizeString ( searchQuery . value ) ; 
@@ -256,15 +254,24 @@ const app = createApp({
256254            return  matches ; 
257255        } 
258256
259-         watchEffect ( ( )  =>  { 
260-             expandedTocs . clear ( ) ; 
261-             const   query   =   normalizeString ( searchQuery . value ) ; 
262-             tocData . forEach ( item   =>   { 
263-                 if   ( filterItem ( item ,   query ) )  { 
257+         watch ( searchQuery ,   ( newQuery )  =>  { 
258+             if   ( ! newQuery )   { 
259+                  expandedTocs . clear ( ) ; 
260+                  // If a search query is removed, open the TOC for the current page. 
261+                 for   ( const   item   of   currentPage )  { 
264262                    expandedTocs . add ( item . key ) ; 
265-                     console . log ( "Added " ,  item . key ) ; 
266263                } 
267-             } ) ; 
264+             } 
265+             else  { 
266+                 expandedTocs . clear ( ) ; 
267+                 const  query  =  normalizeString ( newQuery ) ; 
268+                 tocData . forEach ( item  =>  { 
269+                     if  ( filterItem ( item ,  query ) )  { 
270+                         expandedTocs . add ( item . key ) ; 
271+                         console . log ( "Added " ,  item . key ) ; 
272+                     } 
273+                 } ) ; 
274+             } 
268275        } ) ; 
269276
270277        function  normalizeString ( str )  { 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments