Skip to content

Commit 8769280

Browse files
committed
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.
1 parent b07c408 commit 8769280

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

docs/troubleshooting.md

+9
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,12 @@ syntax highlighting.
2020
`zsh-syntax-highlighting.zsh` does not wrap or bind all the special `zle-*`
2121
widgets provided by zsh. Since the `zle-*` namespace is special, custom
2222
widgets should not be named that way.
23+
24+
25+
### Highlighting in an isearch minibuffer does not work
26+
27+
In `zsh` versions before v5.3 it is not possible to know if an isearch
28+
minibuffer is active and parts of the text should be underlined (or
29+
otherwise higlighted). Therefore it is not possible to apply hihlighting
30+
by `zsh-syntax-highlighting.zsh` while still highlighting the matched part
31+
of the search.

zsh-syntax-highlighting.zsh

+10
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ _zsh_highlight()
6262
# Store the previous command return code to restore it whatever happens.
6363
local ret=$?
6464

65+
# Do not highlight in isearch if ISEARCH_ACTIVE is unsupported (zsh < 5.3).
66+
if [[ $WIDGET == zle-isearch-update ]] && ! (( $+ISEARCH_ACTIVE )); then
67+
region_highlight=()
68+
return $ret
69+
fi
70+
6571
setopt localoptions warncreateglobal
6672
setopt localoptions noksharrays
6773
local REPLY # don't leak $REPLY into global scope
@@ -313,6 +319,10 @@ _zsh_highlight_bind_widgets || {
313319
# E.g. remove cursor imprint, don't highlight partial paths, ...
314320
_zsh_highlight_set_or_wrap_special_zle_widget zle-line-finish
315321

322+
# Always wrap special zle-isearch-update widget to be notified of updates in isearch
323+
_zsh_highlight_set_or_wrap_special_zle_widget zle-isearch-update
324+
325+
316326
# Resolve highlighters directory location.
317327
_zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${${0:A}:h}/highlighters}" || {
318328
echo 'zsh-syntax-highlighting: failed loading highlighters, exiting.' >&2

0 commit comments

Comments
 (0)