From 5b378b988a9f3c350f1687a99445a80ebde7ab68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9leste=20Wouters?= Date: Wed, 22 May 2024 11:23:55 +0200 Subject: [PATCH] Fix colors not being reset on accept w/ recent ZSH (fixes #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. --- src/highlight.zsh | 4 +++- zsh-autosuggestions.zsh | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/highlight.zsh b/src/highlight.zsh index 273c03d5..4dfc6608 100644 --- a/src/highlight.zsh +++ b/src/highlight.zsh @@ -8,7 +8,9 @@ _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}") + if (( $#region_highlight )); then + shift -p region_highlight + fi unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT fi } diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index b19cac73..03100b99 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -244,7 +244,9 @@ _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}") + if (( $#region_highlight )); then + shift -p region_highlight + fi unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT fi }