Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where partial accept duplicates last word #507

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

ericfreese
Copy link
Member

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

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
@ericfreese
Copy link
Member Author

ericfreese commented Jan 30, 2020

CI is being flaky since the async-by-default PR went in. It looks like with_history spec helper is not working right. Seems to be entering the history commands only partially.

@tojin12341za
Copy link

Duplicate of #

@stevenxxiu
Copy link

👍 This fixes the issue for me, when it occurs when I use a custom widget:

$ zsh -df
$ source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
$ function key-cright() {
  zle vi-forward-word -- $@
}
zle -N key-cright
bindkey $'\e[1;5C' key-cright
ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS+=(key-cright)

I'm not sure why unset POSTDISPLAY fixes the issue. Is it because POSTDISPLAY is used in _zsh_autosuggest_highlight_apply()?

@arisu2718
Copy link

Thanks, your fix works for me. Didn't even think I could resolve this issue so fast :D

@mojolo
Copy link

mojolo commented Jun 7, 2023

Thumbs up to @ericfreese. In my case, this commit fixes the duplicating problem with a custom forward-word widget, even without any syntax-highlighting plugin loaded (see below).

The duplicating the last word upon partial acceptance of the last word issue has existed in various forms for several years now. It seems to happen to some people when using zsh-syntax-highlighting, fast-syntax-highlighting, vi-forward-word keybinds, or custom keybinds, etc.

This unset POSTDISPLAY commit seems to fix it in most/all cases. Is there a reason we can't get this commit pushed to the main branch?

  for-word-coarse() {
    local WORDCHARS='*?_-.[]~=/&:;!#$%^(){}<>' 		# All chars are Wordchars (zsh default plus)
    zle forward-word
  }
  zle -N for-word-coarse
  bindkey '^[[1;5C' for-word-coarse                  # [Ctrl+Right] move forward to next non-blank character
  ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS+=(for-word-coarse)

EDIT: It turns out I didn't need to create the custom widget above and could just use the built-in vi-forward-blank-word widget to accomplish the same thing. Using the built-in widget, my duplicating the last word upon partial acceptance of the last word problem goes away. So, I'm a happy camper now. :) Nonetheless, it seems that custom widgets still cause issues with zsh-autosuggestions.

To sum up, the code above causes the duplicating the last word upon partial acceptance of the last word issue but the code below does not:

bindkey '^[[1;5C' vi-forward-blank-word             # [Ctrl+Right] move forward to next non-blank character

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants