mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2025-07-24 13:36:26 +08:00

The ZSH manual describes `region_highlight` as being an array in https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting, therefore the previous strategy of removing as many characters as the last suggestion is *not* the way to do it, explaining why it broke on recent ZSH versions. Replace this logic with a simple last-element delete. Keeps the `_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT` variable intact since there's no downside in tracking its content, as it still used as a marker for whether a suggestion highlight was applied.
29 lines
886 B
Bash
29 lines
886 B
Bash
|
|
#--------------------------------------------------------------------#
|
|
# Highlighting #
|
|
#--------------------------------------------------------------------#
|
|
|
|
# If there was a highlight, remove it
|
|
_zsh_autosuggest_highlight_reset() {
|
|
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
|
|
|
if [[ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]]; then
|
|
if (( $#region_highlight )); then
|
|
shift -p region_highlight
|
|
fi
|
|
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
|
fi
|
|
}
|
|
|
|
# If there's a suggestion, highlight it
|
|
_zsh_autosuggest_highlight_apply() {
|
|
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
|
|
|
if (( $#POSTDISPLAY )); then
|
|
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE"
|
|
region_highlight+=("$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT")
|
|
else
|
|
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
|
fi
|
|
}
|