Fix tab selection

There are currently several subtle bugs with search result tab selection. Which this fixes.

They are each quite involved, so I haven't written them up here, but I am happy to do so if wanted. The main one is that we wouldn't remember the user's tab selection for a follow up search.