From 87692808e06d8fd8ce329a451aa16469ddada354 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Tue, 29 Mar 2016 22:13:46 +0200 Subject: [PATCH] don't highlight in isearch if ISEARCH_ACTIVE is unsupported Old version of zsh don't expose ISEARCH_ACTIVE. Therefore we are unable to re-apply zle_highlight on top and it is impossible to see the underlined area. Completely disable highlighting in isearch in that case. To do that, we need to make sure we are actually called when something changes in isearch. Trumps #257. --- docs/troubleshooting.md | 9 +++++++++ zsh-syntax-highlighting.zsh | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index ebf81f9db..909c4d89d 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -20,3 +20,12 @@ syntax highlighting. `zsh-syntax-highlighting.zsh` does not wrap or bind all the special `zle-*` widgets provided by zsh. Since the `zle-*` namespace is special, custom widgets should not be named that way. + + +### Highlighting in an isearch minibuffer does not work + +In `zsh` versions before v5.3 it is not possible to know if an isearch +minibuffer is active and parts of the text should be underlined (or +otherwise higlighted). Therefore it is not possible to apply hihlighting +by `zsh-syntax-highlighting.zsh` while still highlighting the matched part +of the search. diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index fc9a2639d..9a0ad703f 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -62,6 +62,12 @@ _zsh_highlight() # Store the previous command return code to restore it whatever happens. local ret=$? + # Do not highlight in isearch if ISEARCH_ACTIVE is unsupported (zsh < 5.3). + if [[ $WIDGET == zle-isearch-update ]] && ! (( $+ISEARCH_ACTIVE )); then + region_highlight=() + return $ret + fi + setopt localoptions warncreateglobal setopt localoptions noksharrays local REPLY # don't leak $REPLY into global scope @@ -313,6 +319,10 @@ _zsh_highlight_bind_widgets || { # E.g. remove cursor imprint, don't highlight partial paths, ... _zsh_highlight_set_or_wrap_special_zle_widget zle-line-finish +# Always wrap special zle-isearch-update widget to be notified of updates in isearch +_zsh_highlight_set_or_wrap_special_zle_widget zle-isearch-update + + # Resolve highlighters directory location. _zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${${0:A}:h}/highlighters}" || { echo 'zsh-syntax-highlighting: failed loading highlighters, exiting.' >&2