Skip to content

Commit a8fe22d

Browse files
m0viedanielshahaf
authored andcommitted
driver: Don't highlight in isearch
zsh version 5.2 and lower don't support ISEARCHMATCH_ACTIVE 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. The FAQ entry presupposes #245 will be fixed (in time for the release) too.
1 parent 5bae621 commit a8fe22d

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ 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+
_This problem is fixed in zsh 5.3 and newer._
38+
39+
Highlighting the command line during an incremental history search
40+
(with the `history-incremental-search-backward` widget, which is
41+
bound by default to <kbd>Ctrl+R</kbd> in zsh's emacs keymap) requires zsh 5.3
42+
or newer.
43+
44+
Under zsh 5.2 and older, the zsh-default underlining of the matched portion
45+
of the buffer remains available, but zsh-syntax-highlighting's additional
46+
highlighting is unavailable. (Those versions of zsh do not provide enough
47+
information to allow computing the highlighting correctly.)
48+
49+
See [issue #288][i288] for details.
50+
51+
[i288]: https://github.com/zsh-users/zsh-syntax-highlighting/pull/288
52+
3553
### How are new releases announced?
3654

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

zsh-syntax-highlighting.zsh

Lines changed: 11 additions & 0 deletions
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+
# For details see FAQ entry 'Why does syntax highlighting not work while searching history?'.
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
@@ -258,6 +265,10 @@ _zsh_highlight_bind_widgets()
258265
# E.g. remove cursor imprint, don't highlight partial paths, ...
259266
widgets_to_bind+=(zle-line-finish)
260267

268+
# Always wrap special zle-isearch-update widget to be notified of updates in isearch.
269+
# This is needed because we need to disable highlighting in that case.
270+
widgets_to_bind+=(zle-isearch-update)
271+
261272
local cur_widget
262273
for cur_widget in $widgets_to_bind; do
263274
case $widgets[$cur_widget] in

0 commit comments

Comments
 (0)