fix: allow completion strategy to fallback to history

When completion finds no results, unset suggestion to allow the next
strategy to run instead of blocking with the original input text.
This commit is contained in:
sownt 2025-11-03 13:44:21 +07:00
commit 22ffb41e33
2 changed files with 9 additions and 3 deletions

View file

@ -130,6 +130,9 @@ _zsh_autosuggest_strategy_completion() {
# the second null byte, so trim those off the end. # the second null byte, so trim those off the end.
# See http://www.zsh.org/mla/workers/2015/msg03290.html # See http://www.zsh.org/mla/workers/2015/msg03290.html
suggestion="${${(@0)line}[2]}" suggestion="${${(@0)line}[2]}"
# If the suggestion is the same as the input, treat it as no suggestion
[[ "$suggestion" == "$1" ]] && unset suggestion
} always { } always {
# Destroy the pty # Destroy the pty
zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME

View file

@ -3,7 +3,7 @@
# v0.7.1 # v0.7.1
# Copyright (c) 2013 Thiago de Arruda # Copyright (c) 2013 Thiago de Arruda
# Copyright (c) 2016-2021 Eric Freese # Copyright (c) 2016-2021 Eric Freese
# #
# Permission is hereby granted, free of charge, to any person # Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation # obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without # files (the "Software"), to deal in the Software without
@ -12,10 +12,10 @@
# copies of the Software, and to permit persons to whom the # copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following # Software is furnished to do so, subject to the following
# conditions: # conditions:
# #
# The above copyright notice and this permission notice shall be # The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software. # included in all copies or substantial portions of the Software.
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -625,6 +625,9 @@ _zsh_autosuggest_strategy_completion() {
# the second null byte, so trim those off the end. # the second null byte, so trim those off the end.
# See http://www.zsh.org/mla/workers/2015/msg03290.html # See http://www.zsh.org/mla/workers/2015/msg03290.html
suggestion="${${(@0)line}[2]}" suggestion="${${(@0)line}[2]}"
# If the suggestion is the same as the input, treat it as no suggestion
[[ "$suggestion" == "$1" ]] && unset suggestion
} always { } always {
# Destroy the pty # Destroy the pty
zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME