Skip to content

Commit

Permalink
don't highlight in isearch if ISEARCH_ACTIVE is unsupported
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
m0vie committed Apr 2, 2016
1 parent b07c408 commit 8769280
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
10 changes: 10 additions & 0 deletions zsh-syntax-highlighting.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8769280

Please sign in to comment.