smarter way of moving the autocomplete
fixed the broken autocomplete selection that was introduced a few commits ago