Skip to content

Commit 5b378b9

Browse files
committed
Fix colors not being reset on accept w/ recent ZSH (fixes zsh-users#789)
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.
1 parent c3d4e57 commit 5b378b9

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/highlight.zsh

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ _zsh_autosuggest_highlight_reset() {
88
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
99

1010
if [[ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]]; then
11-
region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}")
11+
if (( $#region_highlight )); then
12+
shift -p region_highlight
13+
fi
1214
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
1315
fi
1416
}

zsh-autosuggestions.zsh

+3-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ _zsh_autosuggest_highlight_reset() {
244244
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
245245

246246
if [[ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]]; then
247-
region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}")
247+
if (( $#region_highlight )); then
248+
shift -p region_highlight
249+
fi
248250
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
249251
fi
250252
}

0 commit comments

Comments
 (0)