Skip to content

Commit a6c1e86

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 a8582ff commit a6c1e86

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 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

+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 (underlining done by zsh is more important in this case).
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)