diff --git a/src/widgets.zsh b/src/widgets.zsh index 33c590c..bd61666 100644 --- a/src/widgets.zsh +++ b/src/widgets.zsh @@ -61,20 +61,9 @@ _zsh_autosuggest_modify() { return $retval fi - # Optimize if manually typing in the suggestion - if (( $#BUFFER > $#orig_buffer )); then - local added=${BUFFER#$orig_buffer} - - # If the string added matches the beginning of the postdisplay - if [[ "$added" = "${orig_postdisplay:0:$#added}" ]]; then - POSTDISPLAY="${orig_postdisplay:$#added}" - return $retval - fi - fi - - # Don't fetch a new suggestion if the buffer hasn't changed - if [[ "$BUFFER" = "$orig_buffer" ]]; then - POSTDISPLAY="$orig_postdisplay" + # Optimize if manually typing in the suggestion or if buffer hasn't changed + if [[ "$BUFFER" = "$orig_buffer"* && "$orig_postdisplay" = "${BUFFER:$#orig_buffer}"* ]]; then + POSTDISPLAY="${orig_postdisplay:$(($#BUFFER - $#orig_buffer))}" return $retval fi diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 21a4b42..1eda1b1 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -323,20 +323,9 @@ _zsh_autosuggest_modify() { return $retval fi - # Optimize if manually typing in the suggestion - if (( $#BUFFER > $#orig_buffer )); then - local added=${BUFFER#$orig_buffer} - - # If the string added matches the beginning of the postdisplay - if [[ "$added" = "${orig_postdisplay:0:$#added}" ]]; then - POSTDISPLAY="${orig_postdisplay:$#added}" - return $retval - fi - fi - - # Don't fetch a new suggestion if the buffer hasn't changed - if [[ "$BUFFER" = "$orig_buffer" ]]; then - POSTDISPLAY="$orig_postdisplay" + # Optimize if manually typing in the suggestion or if buffer hasn't changed + if [[ "$BUFFER" = "$orig_buffer"* && "$orig_postdisplay" = "${BUFFER:$#orig_buffer}"* ]]; then + POSTDISPLAY="${orig_postdisplay:$(($#BUFFER - $#orig_buffer))}" return $retval fi