mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-12-27 22:43:41 +08:00
Only fetch a new suggestion if buffer has changed
This commit is contained in:
parent
a44aa59321
commit
b377c39d0e
|
@ -82,7 +82,7 @@ This plugin works by triggering custom behavior when certain [zle widgets](http:
|
|||
- `ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS`: Widgets in this array will partially accept the suggestion when invoked.
|
||||
- `ZSH_AUTOSUGGEST_IGNORE_WIDGETS`: Widgets in this array will not trigger any custom behavior.
|
||||
|
||||
Widgets not in any of these lists will update the suggestion when invoked.
|
||||
Widgets that modify the buffer and are not found in any of these arrays will fetch a new suggestion after they are invoked.
|
||||
|
||||
**Note:** A widget shouldn't belong to more than one of the above arrays.
|
||||
|
||||
|
|
|
@ -15,13 +15,23 @@ _zsh_autosuggest_clear() {
|
|||
_zsh_autosuggest_modify() {
|
||||
local -i retval
|
||||
|
||||
# Save the contents of the buffer/postdisplay
|
||||
local orig_buffer="$BUFFER"
|
||||
local orig_postdisplay="$POSTDISPLAY"
|
||||
|
||||
# Clear suggestion while original widget runs
|
||||
unset POSTDISPLAY
|
||||
|
||||
# Original widget modifies the buffer
|
||||
# Original widget may modify the buffer
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
retval=$?
|
||||
|
||||
# Don't fetch a new suggestion if the buffer hasn't changed
|
||||
if [ "$BUFFER" = "$orig_buffer" ]; then
|
||||
POSTDISPLAY="$orig_postdisplay"
|
||||
return $retval
|
||||
fi
|
||||
|
||||
# Get a new suggestion if the buffer is not empty after modification
|
||||
local suggestion
|
||||
if [ $#BUFFER -gt 0 ]; then
|
||||
|
|
|
@ -256,13 +256,23 @@ _zsh_autosuggest_clear() {
|
|||
_zsh_autosuggest_modify() {
|
||||
local -i retval
|
||||
|
||||
# Save the contents of the buffer/postdisplay
|
||||
local orig_buffer="$BUFFER"
|
||||
local orig_postdisplay="$POSTDISPLAY"
|
||||
|
||||
# Clear suggestion while original widget runs
|
||||
unset POSTDISPLAY
|
||||
|
||||
# Original widget modifies the buffer
|
||||
# Original widget may modify the buffer
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
retval=$?
|
||||
|
||||
# Don't fetch a new suggestion if the buffer hasn't changed
|
||||
if [ "$BUFFER" = "$orig_buffer" ]; then
|
||||
POSTDISPLAY="$orig_postdisplay"
|
||||
return $retval
|
||||
fi
|
||||
|
||||
# Get a new suggestion if the buffer is not empty after modification
|
||||
local suggestion
|
||||
if [ $#BUFFER -gt 0 ]; then
|
||||
|
|
Loading…
Reference in New Issue
Block a user