@@ -54,7 +54,11 @@ export const GifSearchService = GObject.registerClass(
5454 if ( ! searchWidget ?. visible ) return false ;
5555
5656 const normalizedQuery = typeof query === 'string' ? query . trim ( ) : '' ;
57+ this . _searchDebouncer . cancel ( ) ;
58+ this . _suppressSearchInput = true ;
5759 this . _searchComponent . setSearchText ( normalizedQuery , { focus : false } ) ;
60+ this . _suppressSearchInput = false ;
61+
5862 await this . performExternalSearch ( normalizedQuery ) ;
5963
6064 return true ;
@@ -68,7 +72,6 @@ export const GifSearchService = GObject.registerClass(
6872 const searchWidget = this . _searchComponent ?. getWidget ( ) ;
6973 if ( ! searchWidget ?. visible ) return false ;
7074
71- this . _searchComponent . setSearchText ( '' , { focus : false } ) ;
7275 this . clearSearch ( ) ;
7376 return true ;
7477 }
@@ -150,16 +153,17 @@ export const GifSearchService = GObject.registerClass(
150153 * @param {string } query The search query.
151154 */
152155 async performExternalSearch ( query ) {
153- this . clearSearch ( ) ;
154- this . _suppressSearchInput = true ;
156+ const normalizedQuery = typeof query === 'string' ? query . trim ( ) : '' ;
157+ this . _searchDebouncer . cancel ( ) ;
155158
156- if ( query && query . length >= 1 ) {
157- this . _currentSearchQuery = query ;
159+ if ( normalizedQuery . length >= 1 ) {
160+ this . _currentSearchQuery = normalizedQuery ;
158161 const sessionId = this . _fetchService . startNewSession ( ) ;
159- await this . _fetchService . fetchSearch ( query , sessionId ) ;
162+ await this . _fetchService . fetchSearch ( normalizedQuery , sessionId ) ;
163+ return ;
160164 }
161165
162- this . _suppressSearchInput = false ;
166+ this . clearSearch ( ) ;
163167 }
164168
165169 /**
0 commit comments