diff --git a/README.md b/README.md index ac8beafab..feab82e80 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,15 @@ custom widgets have been created (i.e., after all `zle -N` calls and after running `compinit`). Widgets created later will work, but will not update the syntax highlighting. +### Why does syntax highlighting not work while searching history? + +In current `zsh` versions it is not possible for `zsh-syntax-highlighting.zsh` +to know if an incremental search is currently active and that matched parts of the +buffer should be underlined (or otherwise highlighted). Therefore, it is not possible +for `zsh-syntax-highlighting.zsh` to apply syntax highlighting and to underline the +matched part of the search. While searching the history, the latter is more important, +so syntax highlighting is disabled in this case. + ### How are new releases announced? There is currently no "push" announcements channel. However, the following diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 634bbc24f..84508d609 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 (underlining done by zsh is more important in this case). + 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