mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-11-18 09:51:06 +01:00
Fix issue where partial accept duplicates last word
When z-sy-h is enabled after autosuggestion widgets have already been
bound, partial accepting the last part of a suggestion will result in
that string being duplicated.
I was able to reproduce using the following versions of the two plugins:
- z-sy-h: dde84e1b25f059a298ce3189cddfd0778f998df3
- z-asug: ae315ded4d
and running the following commands interactively one after another:
```
zsh -df
% source path/to/zsh-autosuggestions.zsh
% source path/to/zsh-syntax-highlighting.zsh
% bindkey -e
% bindkey <alt-f> # shows 'bindkey -e-e'
```
The order of the `source` statements matters and the issue cannot be
reproduced if the two source statements are executed together on one
line.
The problem is very similar to this one:
https://github.com/zsh-users/zsh-autosuggestions/issues/126#issuecomment-217121315
See GitHub issue #483
This commit is contained in:
parent
9ad039443f
commit
4ccfdb2435
2 changed files with 10 additions and 4 deletions
|
@ -173,11 +173,13 @@ _zsh_autosuggest_execute() {
|
||||||
_zsh_autosuggest_partial_accept() {
|
_zsh_autosuggest_partial_accept() {
|
||||||
local -i retval cursor_loc
|
local -i retval cursor_loc
|
||||||
|
|
||||||
# Save the contents of the buffer so we can restore later if needed
|
# Save the original buffer/postdisplay so we can restore later if needed
|
||||||
local original_buffer="$BUFFER"
|
local original_buffer="$BUFFER"
|
||||||
|
local original_postdisplay="$POSTDISPLAY"
|
||||||
|
|
||||||
# Temporarily accept the suggestion.
|
# Temporarily accept the suggestion.
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
BUFFER="$BUFFER$POSTDISPLAY"
|
||||||
|
unset POSTDISPLAY
|
||||||
|
|
||||||
# Original widget moves the cursor
|
# Original widget moves the cursor
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
|
@ -197,8 +199,9 @@ _zsh_autosuggest_partial_accept() {
|
||||||
# Clip the buffer at the cursor
|
# Clip the buffer at the cursor
|
||||||
BUFFER="${BUFFER[1,$cursor_loc]}"
|
BUFFER="${BUFFER[1,$cursor_loc]}"
|
||||||
else
|
else
|
||||||
# Restore the original buffer
|
# Restore the original buffer/postdisplay
|
||||||
BUFFER="$original_buffer"
|
BUFFER="$original_buffer"
|
||||||
|
POSTDISPLAY="$original_postdisplay"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return $retval
|
return $retval
|
||||||
|
|
|
@ -435,11 +435,13 @@ _zsh_autosuggest_execute() {
|
||||||
_zsh_autosuggest_partial_accept() {
|
_zsh_autosuggest_partial_accept() {
|
||||||
local -i retval cursor_loc
|
local -i retval cursor_loc
|
||||||
|
|
||||||
# Save the contents of the buffer so we can restore later if needed
|
# Save the original buffer/postdisplay so we can restore later if needed
|
||||||
local original_buffer="$BUFFER"
|
local original_buffer="$BUFFER"
|
||||||
|
local original_postdisplay="$POSTDISPLAY"
|
||||||
|
|
||||||
# Temporarily accept the suggestion.
|
# Temporarily accept the suggestion.
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
BUFFER="$BUFFER$POSTDISPLAY"
|
||||||
|
unset POSTDISPLAY
|
||||||
|
|
||||||
# Original widget moves the cursor
|
# Original widget moves the cursor
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
|
@ -459,8 +461,9 @@ _zsh_autosuggest_partial_accept() {
|
||||||
# Clip the buffer at the cursor
|
# Clip the buffer at the cursor
|
||||||
BUFFER="${BUFFER[1,$cursor_loc]}"
|
BUFFER="${BUFFER[1,$cursor_loc]}"
|
||||||
else
|
else
|
||||||
# Restore the original buffer
|
# Restore the original buffer/postdisplay
|
||||||
BUFFER="$original_buffer"
|
BUFFER="$original_buffer"
|
||||||
|
POSTDISPLAY="$original_postdisplay"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return $retval
|
return $retval
|
||||||
|
|
Loading…
Reference in a new issue