fixes #1700 clear search box if new category is selected

Fixes #1700 
Looks like a lot more changes than it is, I mainly just moved code from inside an event to a defined function that can be called elsewhere.