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:
Eric Freese 2020-01-29 21:30:18 -07:00
parent 9ad039443f
commit 4ccfdb2435
2 changed files with 10 additions and 4 deletions

View File

@ -173,11 +173,13 @@ _zsh_autosuggest_execute() {
_zsh_autosuggest_partial_accept() {
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_postdisplay="$POSTDISPLAY"
# Temporarily accept the suggestion.
BUFFER="$BUFFER$POSTDISPLAY"
unset POSTDISPLAY
# Original widget moves the cursor
_zsh_autosuggest_invoke_original_widget $@
@ -197,8 +199,9 @@ _zsh_autosuggest_partial_accept() {
# Clip the buffer at the cursor
BUFFER="${BUFFER[1,$cursor_loc]}"
else
# Restore the original buffer
# Restore the original buffer/postdisplay
BUFFER="$original_buffer"
POSTDISPLAY="$original_postdisplay"
fi
return $retval

View File

@ -435,11 +435,13 @@ _zsh_autosuggest_execute() {
_zsh_autosuggest_partial_accept() {
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_postdisplay="$POSTDISPLAY"
# Temporarily accept the suggestion.
BUFFER="$BUFFER$POSTDISPLAY"
unset POSTDISPLAY
# Original widget moves the cursor
_zsh_autosuggest_invoke_original_widget $@
@ -459,8 +461,9 @@ _zsh_autosuggest_partial_accept() {
# Clip the buffer at the cursor
BUFFER="${BUFFER[1,$cursor_loc]}"
else
# Restore the original buffer
# Restore the original buffer/postdisplay
BUFFER="$original_buffer"
POSTDISPLAY="$original_postdisplay"
fi
return $retval