Fix #8468. Respect last_idx in prefix searching.

This restores the old behavior of up/down arrow giving history results starting from the most recently accepted result.