File tree 1 file changed +17
-2
lines changed
1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,6 @@ function setupDarkMode() {
90
90
}
91
91
92
92
function setupSearch ( ) {
93
- const searchInput = document . getElementById ( 'search' ) ;
94
93
const onInputChange = debounce ( ( e ) => {
95
94
const searchValue = e . target . value . toLowerCase ( ) ;
96
95
const docNav = document . querySelector ( '.doc-nav' ) ;
@@ -160,7 +159,23 @@ function setupSearch() {
160
159
} ) ;
161
160
}
162
161
} ) ;
163
- searchInput . addEventListener ( 'input' , onInputChange ) ;
162
+ const searchInput = document . querySelector ( '#search input' ) ;
163
+ const url = document . location . toString ( ) ;
164
+ if ( url . includes ( '?' ) ) {
165
+ const query =
166
+ url
167
+ . split ( '?' )
168
+ . slice ( 1 )
169
+ . filter ( ( p ) => p . startsWith ( 'q=' ) )
170
+ . map ( ( p ) => p . replace ( / ^ q = / , '' ) ) [ 0 ] || '' ;
171
+ if ( query ) {
172
+ searchInput . value = query ;
173
+ searchInput . focus ( ) ;
174
+ onInputChange ( { target : { value : query } } ) ;
175
+ }
176
+ }
177
+ const searchInputDiv = document . getElementById ( 'search' ) ;
178
+ searchInputDiv . addEventListener ( 'input' , onInputChange ) ;
164
179
setupSearchKeymaps ( ) ;
165
180
}
166
181
You can’t perform that action at this time.
0 commit comments