Fix bug on up arrow cursor position

Based on https://github.com/robbyrussell/oh-my-zsh/issues/1720