Fixed annoying bug in reverse search while pressing upper arrow key.

The cursor sometimes would go to the wrong place.