From 22ffb41e339f01382f8d8e812311cc8c1698a677 Mon Sep 17 00:00:00 2001 From: sownt Date: Mon, 3 Nov 2025 13:44:21 +0700 Subject: [PATCH] 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. --- src/strategies/completion.zsh | 3 +++ zsh-autosuggestions.zsh | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/strategies/completion.zsh b/src/strategies/completion.zsh index e2d114c..24646e0 100644 --- a/src/strategies/completion.zsh +++ b/src/strategies/completion.zsh @@ -130,6 +130,9 @@ _zsh_autosuggest_strategy_completion() { # the second null byte, so trim those off the end. # See http://www.zsh.org/mla/workers/2015/msg03290.html suggestion="${${(@0)line}[2]}" + + # If the suggestion is the same as the input, treat it as no suggestion + [[ "$suggestion" == "$1" ]] && unset suggestion } always { # Destroy the pty zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index e780225..679bdee 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -3,7 +3,7 @@ # v0.7.1 # Copyright (c) 2013 Thiago de Arruda # Copyright (c) 2016-2021 Eric Freese -# +# # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation # files (the "Software"), to deal in the Software without @@ -12,10 +12,10 @@ # copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following # conditions: -# +# # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. -# +# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES # 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. # See http://www.zsh.org/mla/workers/2015/msg03290.html suggestion="${${(@0)line}[2]}" + + # If the suggestion is the same as the input, treat it as no suggestion + [[ "$suggestion" == "$1" ]] && unset suggestion } always { # Destroy the pty zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME