Skip to content

Commit 6fbeac3

Browse files
committed
don't highlight in isearch
We are unable to re-apply zle_highlight on top in current zsh versions. 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 2ba33bb commit 6fbeac3

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
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 current `zsh` versions 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

Lines changed: 10 additions & 0 deletions
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 (underlining done by zsh is more important in this case).
66+
if [[ $WIDGET == zle-isearch-update ]]; 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
@@ -330,6 +336,10 @@ _zsh_highlight_bind_widgets || {
330336
# E.g. remove cursor imprint, don't highlight partial paths, ...
331337
_zsh_highlight_set_or_wrap_special_zle_widget zle-line-finish
332338

339+
# Always wrap special zle-isearch-update widget to be notified of updates in isearch
340+
_zsh_highlight_set_or_wrap_special_zle_widget zle-isearch-update
341+
342+
333343
# Resolve highlighters directory location.
334344
_zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${${0:A}:h}/highlighters}" || {
335345
echo 'zsh-syntax-highlighting: failed loading highlighters, exiting.' >&2

0 commit comments

Comments
 (0)