Fix: set global search earlier to avoid awaiting debounce (#13865)

This commit is contained in:
shamoon
2026-08-30 10:19:53 -07:00
committed by GitHub
parent b20d707f2a
commit a7ff3a8272
3 changed files with 20 additions and 1 deletions
@@ -9,7 +9,7 @@
autocomplete="off"
spellcheck="false"
[ngModel]="query()"
(ngModelChange)="queryDebounce.next($event)"
(ngModelChange)="onQueryChange($event)"
(keydown)="searchInputKeyDown($event)"
ngbDropdownAnchor>
<div class="position-absolute top-50 end-0 translate-middle">
@@ -272,6 +272,19 @@ describe('GlobalSearchComponent', () => {
expect(advancedSearchSpy).toHaveBeenCalled()
})
it('should set query immediately and run full search on enter without waiting for debounce', () => {
jest.useFakeTimers()
const searchSpy = jest.spyOn(searchService, 'globalSearch')
searchSpy.mockReturnValue(of({} as any))
const fullSearchSpy = jest.spyOn(component, 'runFullSearch')
component.onQueryChange('test')
expect(component.query()).toBe('test')
component.searchInputKeyDown(new KeyboardEvent('keydown', { key: 'Enter' }))
expect(fullSearchSpy).toHaveBeenCalled()
expect(searchSpy).not.toHaveBeenCalled()
jest.useRealTimers()
})
it('should search on query debounce', () => {
jest.useFakeTimers()
const query = 'test'
@@ -119,6 +119,12 @@ export class GlobalSearchComponent implements OnInit {
})
}
public onQueryChange(text: string) {
// set immediately so Enter / the full search button work without waiting for the debounce
this.query.set(text)
this.queryDebounce.next(text)
}
public ngOnInit() {
this.hotkeyService
.addShortcut({ keys: '/', description: $localize`Global search` })