Skip to content

Commit

Permalink
Fix issue where partial accept duplicates last word
Browse files Browse the repository at this point in the history
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: ae315de

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:
  #126 (comment)

See GitHub issue #483
  • Loading branch information
ericfreese committed Jan 30, 2020
1 parent 9ad0394 commit 14af353
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/widgets.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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 $@
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions zsh-autosuggestions.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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 $@
Expand All @@ -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
Expand Down

0 comments on commit 14af353

Please sign in to comment.