Get the latest cursor position before grabing focus

This fixes the misplaced cursor position that happened when typing a
character just as a search started. This caused that the search field
would show text that migth not correspond to what was typed.