mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-11-18 09:51:06 +01:00
Fix #141: Disable suggestions for widgets called from widgets
This commit is contained in:
parent
62cdba4e0f
commit
9fb9675306
6 changed files with 34 additions and 28 deletions
|
@ -22,17 +22,20 @@ _zsh_autosuggest_modify() {
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
retval=$?
|
retval=$?
|
||||||
|
|
||||||
# Get a new suggestion if the buffer is not empty after modification
|
# Only fetch suggestions at the first level of widget recursion
|
||||||
local suggestion
|
if [ -z "${funcstack[(rn:2:)_zsh_autosuggest_widget_*]}" ]; then
|
||||||
if [ $#BUFFER -gt 0 ]; then
|
# Get a new suggestion if the buffer is not empty after modification
|
||||||
suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")"
|
local suggestion
|
||||||
fi
|
if [ $#BUFFER -gt 0 ]; then
|
||||||
|
suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")"
|
||||||
|
fi
|
||||||
|
|
||||||
# Add the suggestion to the POSTDISPLAY
|
# Add the suggestion to the POSTDISPLAY
|
||||||
if [ -n "$suggestion" ]; then
|
if [ -n "$suggestion" ]; then
|
||||||
POSTDISPLAY="${suggestion#$BUFFER}"
|
POSTDISPLAY="${suggestion#$BUFFER}"
|
||||||
else
|
else
|
||||||
unset POSTDISPLAY
|
unset POSTDISPLAY
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return $retval
|
return $retval
|
||||||
|
|
|
@ -24,7 +24,7 @@ testCursorAtEnd() {
|
||||||
|
|
||||||
stub _zsh_autosuggest_invoke_original_widget
|
stub _zsh_autosuggest_invoke_original_widget
|
||||||
|
|
||||||
_zsh_autosuggest_accept 'original-widget'
|
_zsh_autosuggest_widget_accept 'original-widget'
|
||||||
|
|
||||||
assertTrue \
|
assertTrue \
|
||||||
'original widget not invoked' \
|
'original widget not invoked' \
|
||||||
|
@ -48,7 +48,7 @@ testCursorNotAtEnd() {
|
||||||
|
|
||||||
stub _zsh_autosuggest_invoke_original_widget
|
stub _zsh_autosuggest_invoke_original_widget
|
||||||
|
|
||||||
_zsh_autosuggest_accept 'original-widget'
|
_zsh_autosuggest_widget_accept 'original-widget'
|
||||||
|
|
||||||
assertTrue \
|
assertTrue \
|
||||||
'original widget not invoked' \
|
'original widget not invoked' \
|
||||||
|
@ -73,7 +73,7 @@ testViCursorAtEnd() {
|
||||||
|
|
||||||
stub _zsh_autosuggest_invoke_original_widget
|
stub _zsh_autosuggest_invoke_original_widget
|
||||||
|
|
||||||
_zsh_autosuggest_accept 'original-widget'
|
_zsh_autosuggest_widget_accept 'original-widget'
|
||||||
|
|
||||||
assertTrue \
|
assertTrue \
|
||||||
'original widget not invoked' \
|
'original widget not invoked' \
|
||||||
|
@ -98,7 +98,7 @@ testViCursorNotAtEnd() {
|
||||||
|
|
||||||
stub _zsh_autosuggest_invoke_original_widget
|
stub _zsh_autosuggest_invoke_original_widget
|
||||||
|
|
||||||
_zsh_autosuggest_accept 'original-widget'
|
_zsh_autosuggest_widget_accept 'original-widget'
|
||||||
|
|
||||||
assertTrue \
|
assertTrue \
|
||||||
'original widget not invoked' \
|
'original widget not invoked' \
|
||||||
|
|
|
@ -19,7 +19,7 @@ testClear() {
|
||||||
BUFFER='ec'
|
BUFFER='ec'
|
||||||
POSTDISPLAY='ho hello'
|
POSTDISPLAY='ho hello'
|
||||||
|
|
||||||
_zsh_autosuggest_clear 'original-widget'
|
_zsh_autosuggest_widget_clear 'original-widget'
|
||||||
|
|
||||||
assertEquals \
|
assertEquals \
|
||||||
'BUFFER was modified' \
|
'BUFFER was modified' \
|
||||||
|
|
|
@ -25,7 +25,7 @@ testModify() {
|
||||||
_zsh_autosuggest_suggestion \
|
_zsh_autosuggest_suggestion \
|
||||||
'echo hello'
|
'echo hello'
|
||||||
|
|
||||||
_zsh_autosuggest_modify 'original-widget'
|
_zsh_autosuggest_widget_modify 'original-widget'
|
||||||
|
|
||||||
assertTrue \
|
assertTrue \
|
||||||
'original widget not invoked' \
|
'original widget not invoked' \
|
||||||
|
|
|
@ -25,7 +25,7 @@ testCursorMovesOutOfBuffer() {
|
||||||
_zsh_autosuggest_invoke_original_widget \
|
_zsh_autosuggest_invoke_original_widget \
|
||||||
'CURSOR=5; LBUFFER="echo "; RBUFFER="hello"'
|
'CURSOR=5; LBUFFER="echo "; RBUFFER="hello"'
|
||||||
|
|
||||||
_zsh_autosuggest_partial_accept 'original-widget'
|
_zsh_autosuggest_widget_partial_accept 'original-widget'
|
||||||
|
|
||||||
assertTrue \
|
assertTrue \
|
||||||
'original widget not invoked' \
|
'original widget not invoked' \
|
||||||
|
@ -51,7 +51,7 @@ testCursorStaysInBuffer() {
|
||||||
_zsh_autosuggest_invoke_original_widget \
|
_zsh_autosuggest_invoke_original_widget \
|
||||||
'CURSOR=5; LBUFFER="echo "; RBUFFER="hello"'
|
'CURSOR=5; LBUFFER="echo "; RBUFFER="hello"'
|
||||||
|
|
||||||
_zsh_autosuggest_partial_accept 'original-widget'
|
_zsh_autosuggest_widget_partial_accept 'original-widget'
|
||||||
|
|
||||||
assertTrue \
|
assertTrue \
|
||||||
'original widget not invoked' \
|
'original widget not invoked' \
|
||||||
|
|
|
@ -240,17 +240,20 @@ _zsh_autosuggest_modify() {
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
retval=$?
|
retval=$?
|
||||||
|
|
||||||
# Get a new suggestion if the buffer is not empty after modification
|
# Only fetch suggestions at the first level of widget recursion
|
||||||
local suggestion
|
if [ -z "${funcstack[(rn:2:)_zsh_autosuggest_widget_*]}" ]; then
|
||||||
if [ $#BUFFER -gt 0 ]; then
|
# Get a new suggestion if the buffer is not empty after modification
|
||||||
suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")"
|
local suggestion
|
||||||
fi
|
if [ $#BUFFER -gt 0 ]; then
|
||||||
|
suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")"
|
||||||
|
fi
|
||||||
|
|
||||||
# Add the suggestion to the POSTDISPLAY
|
# Add the suggestion to the POSTDISPLAY
|
||||||
if [ -n "$suggestion" ]; then
|
if [ -n "$suggestion" ]; then
|
||||||
POSTDISPLAY="${suggestion#$BUFFER}"
|
POSTDISPLAY="${suggestion#$BUFFER}"
|
||||||
else
|
else
|
||||||
unset POSTDISPLAY
|
unset POSTDISPLAY
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return $retval
|
return $retval
|
||||||
|
|
Loading…
Reference in a new issue