Skip to content

Commit

Permalink
Fix colors not being reset on accept w/ recent ZSH (fixes zsh-users#789)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ElementW committed May 22, 2024
1 parent c3d4e57 commit 77efe98
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/highlight.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ _zsh_autosuggest_highlight_reset() {
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT

if [[ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]]; then
region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}")
shift -p region_highlight
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
fi
}
Expand Down
2 changes: 1 addition & 1 deletion zsh-autosuggestions.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ _zsh_autosuggest_highlight_reset() {
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT

if [[ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]]; then
region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}")
shift -p region_highlight
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
fi
}
Expand Down

0 comments on commit 77efe98

Please sign in to comment.