Disable autosuggest if buffer is too large
Make buffer max size configurable, defaulted to infinity
This commit is contained in:
parent
63816c5da8
commit
7b81eb79b8
|
@ -25,7 +25,9 @@ _zsh_autosuggest_modify() {
|
||||||
# Get a new suggestion if the buffer is not empty after modification
|
# Get a new suggestion if the buffer is not empty after modification
|
||||||
local suggestion
|
local suggestion
|
||||||
if [ $#BUFFER -gt 0 ]; then
|
if [ $#BUFFER -gt 0 ]; then
|
||||||
suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")"
|
if [ -z "$ZSH_BUFFER_MAX_SIZE" -o $#BUFFER -lt "$ZSH_BUFFER_MAX_SIZE" ]; then
|
||||||
|
suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Add the suggestion to the POSTDISPLAY
|
# Add the suggestion to the POSTDISPLAY
|
||||||
|
|
|
@ -9,6 +9,7 @@ oneTimeSetUp() {
|
||||||
setUp() {
|
setUp() {
|
||||||
BUFFER=''
|
BUFFER=''
|
||||||
POSTDISPLAY=''
|
POSTDISPLAY=''
|
||||||
|
ZSH_BUFFER_MAX_SIZE=''
|
||||||
}
|
}
|
||||||
|
|
||||||
tearDown() {
|
tearDown() {
|
||||||
|
@ -42,6 +43,35 @@ testModify() {
|
||||||
"$POSTDISPLAY"
|
"$POSTDISPLAY"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testModifyBufferTooLarge() {
|
||||||
|
|
||||||
|
ZSH_BUFFER_MAX_SIZE='20'
|
||||||
|
|
||||||
|
stub_and_eval \
|
||||||
|
_zsh_autosuggest_invoke_original_widget \
|
||||||
|
'BUFFER+="012345678901234567890"'
|
||||||
|
|
||||||
|
stub_and_echo \
|
||||||
|
_zsh_autosuggest_suggestion \
|
||||||
|
'012345678901234567890123456789'
|
||||||
|
|
||||||
|
_zsh_autosuggest_modify 'original-widget'
|
||||||
|
|
||||||
|
assertTrue \
|
||||||
|
'original widget not invoked' \
|
||||||
|
'stub_called _zsh_autosuggest_invoke_original_widget'
|
||||||
|
|
||||||
|
assertEquals \
|
||||||
|
'BUFFER was not modified' \
|
||||||
|
'012345678901234567890' \
|
||||||
|
"$BUFFER"
|
||||||
|
|
||||||
|
assertEquals \
|
||||||
|
'POSTDISPLAY does not contain suggestion' \
|
||||||
|
'' \
|
||||||
|
"$POSTDISPLAY"
|
||||||
|
}
|
||||||
|
|
||||||
testRetval() {
|
testRetval() {
|
||||||
stub_and_eval \
|
stub_and_eval \
|
||||||
_zsh_autosuggest_invoke_original_widget \
|
_zsh_autosuggest_invoke_original_widget \
|
||||||
|
|
|
@ -243,7 +243,9 @@ _zsh_autosuggest_modify() {
|
||||||
# Get a new suggestion if the buffer is not empty after modification
|
# Get a new suggestion if the buffer is not empty after modification
|
||||||
local suggestion
|
local suggestion
|
||||||
if [ $#BUFFER -gt 0 ]; then
|
if [ $#BUFFER -gt 0 ]; then
|
||||||
suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")"
|
if [ -z "$ZSH_BUFFER_MAX_SIZE" -o $#BUFFER -lt "$ZSH_BUFFER_MAX_SIZE" ]; then
|
||||||
|
suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Add the suggestion to the POSTDISPLAY
|
# Add the suggestion to the POSTDISPLAY
|
||||||
|
|
Loading…
Reference in New Issue