Fix #141: Disable suggestions for widgets called from widgets

This commit is contained in:
Eric Freese 2016-04-29 14:46:24 -06:00
parent 62cdba4e0f
commit 9fb9675306
6 changed files with 34 additions and 28 deletions

View file

@ -22,17 +22,20 @@ _zsh_autosuggest_modify() {
_zsh_autosuggest_invoke_original_widget $@
retval=$?
# Get a new suggestion if the buffer is not empty after modification
local suggestion
if [ $#BUFFER -gt 0 ]; then
suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")"
fi
# Only fetch suggestions at the first level of widget recursion
if [ -z "${funcstack[(rn:2:)_zsh_autosuggest_widget_*]}" ]; then
# Get a new suggestion if the buffer is not empty after modification
local suggestion
if [ $#BUFFER -gt 0 ]; then
suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")"
fi
# Add the suggestion to the POSTDISPLAY
if [ -n "$suggestion" ]; then
POSTDISPLAY="${suggestion#$BUFFER}"
else
unset POSTDISPLAY
# Add the suggestion to the POSTDISPLAY
if [ -n "$suggestion" ]; then
POSTDISPLAY="${suggestion#$BUFFER}"
else
unset POSTDISPLAY
fi
fi
return $retval

View file

@ -24,7 +24,7 @@ testCursorAtEnd() {
stub _zsh_autosuggest_invoke_original_widget
_zsh_autosuggest_accept 'original-widget'
_zsh_autosuggest_widget_accept 'original-widget'
assertTrue \
'original widget not invoked' \
@ -48,7 +48,7 @@ testCursorNotAtEnd() {
stub _zsh_autosuggest_invoke_original_widget
_zsh_autosuggest_accept 'original-widget'
_zsh_autosuggest_widget_accept 'original-widget'
assertTrue \
'original widget not invoked' \
@ -73,7 +73,7 @@ testViCursorAtEnd() {
stub _zsh_autosuggest_invoke_original_widget
_zsh_autosuggest_accept 'original-widget'
_zsh_autosuggest_widget_accept 'original-widget'
assertTrue \
'original widget not invoked' \
@ -98,7 +98,7 @@ testViCursorNotAtEnd() {
stub _zsh_autosuggest_invoke_original_widget
_zsh_autosuggest_accept 'original-widget'
_zsh_autosuggest_widget_accept 'original-widget'
assertTrue \
'original widget not invoked' \

View file

@ -19,7 +19,7 @@ testClear() {
BUFFER='ec'
POSTDISPLAY='ho hello'
_zsh_autosuggest_clear 'original-widget'
_zsh_autosuggest_widget_clear 'original-widget'
assertEquals \
'BUFFER was modified' \

View file

@ -25,7 +25,7 @@ testModify() {
_zsh_autosuggest_suggestion \
'echo hello'
_zsh_autosuggest_modify 'original-widget'
_zsh_autosuggest_widget_modify 'original-widget'
assertTrue \
'original widget not invoked' \

View file

@ -25,7 +25,7 @@ testCursorMovesOutOfBuffer() {
_zsh_autosuggest_invoke_original_widget \
'CURSOR=5; LBUFFER="echo "; RBUFFER="hello"'
_zsh_autosuggest_partial_accept 'original-widget'
_zsh_autosuggest_widget_partial_accept 'original-widget'
assertTrue \
'original widget not invoked' \
@ -51,7 +51,7 @@ testCursorStaysInBuffer() {
_zsh_autosuggest_invoke_original_widget \
'CURSOR=5; LBUFFER="echo "; RBUFFER="hello"'
_zsh_autosuggest_partial_accept 'original-widget'
_zsh_autosuggest_widget_partial_accept 'original-widget'
assertTrue \
'original widget not invoked' \

View file

@ -240,17 +240,20 @@ _zsh_autosuggest_modify() {
_zsh_autosuggest_invoke_original_widget $@
retval=$?
# Get a new suggestion if the buffer is not empty after modification
local suggestion
if [ $#BUFFER -gt 0 ]; then
suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")"
fi
# Only fetch suggestions at the first level of widget recursion
if [ -z "${funcstack[(rn:2:)_zsh_autosuggest_widget_*]}" ]; then
# Get a new suggestion if the buffer is not empty after modification
local suggestion
if [ $#BUFFER -gt 0 ]; then
suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")"
fi
# Add the suggestion to the POSTDISPLAY
if [ -n "$suggestion" ]; then
POSTDISPLAY="${suggestion#$BUFFER}"
else
unset POSTDISPLAY
# Add the suggestion to the POSTDISPLAY
if [ -n "$suggestion" ]; then
POSTDISPLAY="${suggestion#$BUFFER}"
else
unset POSTDISPLAY
fi
fi
return $retval