Updates to Kickoff search results should always highlight an item
Occasionally in Kickoff, due to a race condition, the user can type a search and the search results will appear, but the top item in the results will not be highlighted.
When this happens, it breaks this common user flow:
- User opens Kickoff with the intent to launch an app (e.x. Firefox)
- User types "fi", sees Firefox appear as the top result, then they hit "enter" in the keyboard to launch it.
Expected:
Firefox (or whatever the top result is) launches
Actual:
The top result does not launch, because it is not highlighted, due to a race condition that resets currentIndex to -1 (which means: nothing is highlighted)
You can reproduce this issue by launching Kickoff and typing a query -- eventually, the race condition I described will break the scenario. I can reproduce this consistently on multiple environments (my desktop, laptop, and VM).
This is incredibly frustrating, because about 20% of the time, the extremely common flow of "launch Kickoff -> type a few keys -> hit enter" does not work at all.
After investigating for hours, I could not find the source of the race condition, which is resetting currentIndex to -1 (instead of keeping it at the default 0, which means "The top result"). The fix in this MR is therefore a bit of a workaround, to check if nothing is highlighted in the search results, and if that's the case make sure we default to the top result being highlighted.
Since we always guarantee some result is highlighted, then we know hitting "enter" on the keyboard will always trigger some result, instead of doing nothing.