I get it now, your implementation depends on the `prefix` not being in the `historyBuffer`. If it is in the `historyBuffer`, you use the `previousPrefix`.

This is a rather poor assumption, since it's not unlikely for `prefix` to match a previous search term or ex command. It would be better to maintain extra state about whether the value in the input is user entered or autocompleted.