mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-12-23 10:21:15 +01:00
Merge pull request #178 from lbolla/issue141-develop
Disable autosuggest if buffer is too large
This commit is contained in:
commit
472394681e
5 changed files with 48 additions and 2 deletions
|
@ -86,6 +86,12 @@ Widgets not in any of these lists will update the suggestion when invoked.
|
|||
**Note:** A widget shouldn't belong to more than one of the above arrays.
|
||||
|
||||
|
||||
### Disabling suggestion for large buffers
|
||||
|
||||
Set `ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE` to an integer value to disable autosuggestion for large buffers. The default is unset, which means that autosuggestion will be tried for any buffer size. Recommended value is 20.
|
||||
This can be useful when pasting large amount of text in the terminal, to avoid triggering autosuggestion for too long strings.
|
||||
|
||||
|
||||
### Key Bindings
|
||||
|
||||
This plugin provides three widgets that you can use with `bindkey`:
|
||||
|
|
|
@ -47,3 +47,6 @@ ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
|
|||
vi-forward-blank-word
|
||||
vi-forward-blank-word-end
|
||||
)
|
||||
|
||||
# Max size of buffer to trigger autosuggestion. Leave undefined for no upper bound.
|
||||
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=
|
||||
|
|
|
@ -25,7 +25,9 @@ _zsh_autosuggest_modify() {
|
|||
# Get a new suggestion if the buffer is not empty after modification
|
||||
local suggestion
|
||||
if [ $#BUFFER -gt 0 ]; then
|
||||
suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")"
|
||||
if [ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" -o $#BUFFER -lt "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]; then
|
||||
suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Add the suggestion to the POSTDISPLAY
|
||||
|
|
|
@ -9,6 +9,7 @@ oneTimeSetUp() {
|
|||
setUp() {
|
||||
BUFFER=''
|
||||
POSTDISPLAY=''
|
||||
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=''
|
||||
}
|
||||
|
||||
tearDown() {
|
||||
|
@ -42,6 +43,35 @@ testModify() {
|
|||
"$POSTDISPLAY"
|
||||
}
|
||||
|
||||
testModifyBufferTooLarge() {
|
||||
|
||||
ZSH_AUTOSUGGEST_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() {
|
||||
stub_and_eval \
|
||||
_zsh_autosuggest_invoke_original_widget \
|
||||
|
|
|
@ -74,6 +74,9 @@ ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
|
|||
vi-forward-blank-word-end
|
||||
)
|
||||
|
||||
# Max size of buffer to trigger autosuggestion. Leave undefined for no upper bound.
|
||||
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Handle Deprecated Variables/Widgets #
|
||||
#--------------------------------------------------------------------#
|
||||
|
@ -243,7 +246,9 @@ _zsh_autosuggest_modify() {
|
|||
# Get a new suggestion if the buffer is not empty after modification
|
||||
local suggestion
|
||||
if [ $#BUFFER -gt 0 ]; then
|
||||
suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")"
|
||||
if [ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" -o $#BUFFER -lt "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]; then
|
||||
suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Add the suggestion to the POSTDISPLAY
|
||||
|
|
Loading…
Reference in a new issue