zsh-users / zsh-autosuggestions

Fish-like autosuggestions for zsh
MIT License
30.81k stars 1.85k forks source link

async mode breaks the history-search-end zle widget #619

Open doy opened 3 years ago

doy commented 3 years ago

Describe the bug

async mode was recently enabled by default, and when used, history-search-end doesn't work properly. the exact way it fails is a bit inconsistent - it feels like there is a race condition or something. most commonly you need to press the key it is bound to multiple times to get it to do anything, and eventually it stops searching through history at all.

To Reproduce

Steps to reproduce the behavior:

# .zshrc
export HISTFILE=$HOME/.zsh_history
export HISTSIZE=1000
export SAVEHIST=1000

autoload history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey "^[OA" history-beginning-search-backward-end # or "^[[A" depending on your terminal
bindkey "^[OB" history-beginning-search-forward-end  # or "^[[B" depending on your terminal

source ~/zsh-autosuggestions/zsh-autosuggestions.zsh
# unset ZSH_AUTOSUGGEST_USE_ASYNC

if you populate your history with a few commands that share a prefix, you should see it working properly if you uncomment the unset line, but break if you comment it out. for instance, run these commands in sequence:

echo foo
ls foo
echo bar
ls bar
echo baz
ls baz
echo quux
ls quux

and then at the prompt, type echo and press the up arrow key a couple times. this should cycle through echo quux, echo baz, echo bar, echo foo on each keypress, but if async mode is enabled, i get echo quux from the first up arrow press, then echo baz, then it stays on echo baz, and going further back through the history requires multiple up arrow presses. eventually if there are enough entries, something else happens where it stops searching any further backward at all.

Expected behavior

the history-search-end widget should work the same way in async mode as it does with async mode disabled

Desktop

ericfreese commented 3 years ago

Hi, I think that this is a similar bug to #241. See https://github.com/zsh-users/zsh-autosuggestions/issues/241#issuecomment-375812886 and https://github.com/zsh-users/zsh-autosuggestions/pull/319

Try adding those widgets to your ZSH_AUTOSUGGEST_CLEAR_WIDGETS via something like this in your zshrc:

ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(history-beginning-search-backward-end history-beginning-search-forward-end)

We can leave this issue open until we update the default value of ZSH_AUTOSUGGEST_CLEAR_WIDGETS to include these widgets as well.