Skip to content

Commit fcc03fe

Browse files
committed
'driver': Don't highlight in isearch
zsh version 5.2 and lower don't support ISEARCHMATCH_ACTIE and we are unable to re-apply zle_highlight on top. Therefore it is impossible to see the underlined matched area. Since that information is more important, 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 276d31e commit fcc03fe

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-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 5.3 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

+11
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ _zsh_highlight()
5858
# Store the previous command return code to restore it whatever happens.
5959
local ret=$?
6060

61+
# Remove all highlighting in isearch, so that only the underlining done by zsh itself remains.
62+
# See FAQ entry 'Why does syntax highlighting not work while searching history?' for details.
63+
if [[ $WIDGET == zle-isearch-update ]]; then
64+
region_highlight=()
65+
return $ret
66+
fi
67+
6168
setopt localoptions warncreateglobal
6269
setopt localoptions noksharrays
6370
local REPLY # don't leak $REPLY into global scope
@@ -243,6 +250,10 @@ _zsh_highlight_bind_widgets()
243250
# E.g. remove cursor imprint, don't highlight partial paths, ...
244251
widgets_to_bind+=(zle-line-finish)
245252

253+
# Always wrap special zle-isearch-update widget to be notified of updates in isearch.
254+
# This is needed because we need to disable highlighting in that case.
255+
widgets_to_bind+=(zle-isearch-update)
256+
246257
local cur_widget
247258
for cur_widget in $widgets_to_bind; do
248259
case $widgets[$cur_widget] in

0 commit comments

Comments
 (0)