Skip to content

Commit 8d04e02

Browse files
committed
don't highlight in isearch if ISEARCH_ACTIVE is unsupported
Old versions 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 c268d43 commit 8d04e02

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ custom widgets have been created (i.e., after all `zle -N` calls and after
3232
running `compinit`). Widgets created later will work, but will not update the
3333
syntax highlighting.
3434

35+
### Why does syntax highlighting not work while searching history?
36+
37+
In `zsh` versions before v5.3 it is not possible for `zsh-syntax-highlighting.zsh`
38+
to know if an incremental search is currently active and that matched parts of the
39+
buffer should be underlined (or otherwise highlighted). Therefore, it is not possible
40+
for `zsh-syntax-highlighting.zsh` to apply syntax highlighting and to underline the
41+
matched part of the search. While searching the history, the latter is more important,
42+
so syntax highlighting is disabled in this case.
43+
3544
### How are new releases announced?
3645

3746
There is currently no "push" announcements channel. However, the following

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)