Skip to content

Commit

Permalink
Fix #141: Disable suggestions for widgets called from widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
ericfreese committed Apr 29, 2016
1 parent e87bc74 commit 7026544
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 29 deletions.
25 changes: 14 additions & 11 deletions src/widgets.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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

# Add the suggestion to the POSTDISPLAY
if [ -n "$suggestion" ]; then
POSTDISPLAY="${suggestion#$BUFFER}"
else
unset POSTDISPLAY
# 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
fi
fi

return $retval
Expand Down
8 changes: 4 additions & 4 deletions test/widgets/accept_test.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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' \
Expand All @@ -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' \
Expand All @@ -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' \
Expand All @@ -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' \
Expand Down
2 changes: 1 addition & 1 deletion test/widgets/clear_test.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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' \
Expand Down
2 changes: 1 addition & 1 deletion test/widgets/modify_test.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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' \
Expand Down
4 changes: 2 additions & 2 deletions test/widgets/partial_accept_test.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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' \
Expand All @@ -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' \
Expand Down
23 changes: 13 additions & 10 deletions zsh-autosuggestions.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7026544

Please sign in to comment.