diff --git a/src-ui/src/app/components/app-frame/global-search/global-search.component.html b/src-ui/src/app/components/app-frame/global-search/global-search.component.html index 06c77ac3d..e2748709e 100644 --- a/src-ui/src/app/components/app-frame/global-search/global-search.component.html +++ b/src-ui/src/app/components/app-frame/global-search/global-search.component.html @@ -9,7 +9,7 @@ autocomplete="off" spellcheck="false" [ngModel]="query()" - (ngModelChange)="queryDebounce.next($event)" + (ngModelChange)="onQueryChange($event)" (keydown)="searchInputKeyDown($event)" ngbDropdownAnchor>
diff --git a/src-ui/src/app/components/app-frame/global-search/global-search.component.spec.ts b/src-ui/src/app/components/app-frame/global-search/global-search.component.spec.ts index a497f3e50..9d0655ca4 100644 --- a/src-ui/src/app/components/app-frame/global-search/global-search.component.spec.ts +++ b/src-ui/src/app/components/app-frame/global-search/global-search.component.spec.ts @@ -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' diff --git a/src-ui/src/app/components/app-frame/global-search/global-search.component.ts b/src-ui/src/app/components/app-frame/global-search/global-search.component.ts index aea247b52..685810c42 100644 --- a/src-ui/src/app/components/app-frame/global-search/global-search.component.ts +++ b/src-ui/src/app/components/app-frame/global-search/global-search.component.ts @@ -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` })