First pass at async functionality
This commit is contained in:
@@ -19,7 +19,7 @@ _zsh_autosuggest_modify() {
|
||||
local orig_buffer="$BUFFER"
|
||||
local orig_postdisplay="$POSTDISPLAY"
|
||||
|
||||
# Clear suggestion while original widget runs
|
||||
# Clear suggestion while waiting for next one
|
||||
unset POSTDISPLAY
|
||||
|
||||
# Original widget may modify the buffer
|
||||
@@ -33,18 +33,12 @@ _zsh_autosuggest_modify() {
|
||||
fi
|
||||
|
||||
# Get a new suggestion if the buffer is not empty after modification
|
||||
local suggestion
|
||||
if [ $#BUFFER -gt 0 ]; then
|
||||
if [ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" -o $#BUFFER -lt "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]; then
|
||||
suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")"
|
||||
_zsh_autosuggest_async_fetch_suggestion "$BUFFER"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Add the suggestion to the POSTDISPLAY
|
||||
if [ -n "$suggestion" ]; then
|
||||
POSTDISPLAY="${suggestion#$BUFFER}"
|
||||
fi
|
||||
|
||||
return $retval
|
||||
}
|
||||
|
||||
@@ -133,3 +127,21 @@ done
|
||||
zle -N autosuggest-accept _zsh_autosuggest_widget_accept
|
||||
zle -N autosuggest-clear _zsh_autosuggest_widget_clear
|
||||
zle -N autosuggest-execute _zsh_autosuggest_widget_execute
|
||||
|
||||
_zsh_autosuggest_show_suggestion() {
|
||||
local suggestion=$1
|
||||
|
||||
_zsh_autosuggest_highlight_reset
|
||||
|
||||
if [ -n "$suggestion" ]; then
|
||||
POSTDISPLAY="${suggestion#$BUFFER}"
|
||||
else
|
||||
unset POSTDISPLAY
|
||||
fi
|
||||
|
||||
_zsh_autosuggest_highlight_apply
|
||||
|
||||
zle -R
|
||||
}
|
||||
|
||||
zle -N _autosuggest-show-suggestion _zsh_autosuggest_show_suggestion
|
||||
|
||||
Reference in New Issue
Block a user