diff --git a/README.md b/README.md index ac8beaf..7f0fe28 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,24 @@ custom widgets have been created (i.e., after all `zle -N` calls and after running `compinit`). Widgets created later will work, but will not update the syntax highlighting. +### Why does syntax highlighting not work while searching history? + +_This problem is fixed in zsh 5.3 and newer._ + +Highlighting the command line during an incremental history search +(with the `history-incremental-search-backward` widget, which is +bound by default to Ctrl+R in zsh's emacs keymap) requires zsh 5.3 +or newer. + +Under zsh 5.2 and older, the zsh-default underlining of the matched portion +of the buffer remains available, but zsh-syntax-highlighting's additional +highlighting is unavailable. (Those versions of zsh do not provide enough +information to allow computing the highlighting correctly.) + +See [issue #288][i288] for details. + +[i288]: https://github.com/zsh-users/zsh-syntax-highlighting/pull/288 + ### How are new releases announced? There is currently no "push" announcements channel. However, the following diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 80f5a4e..de3fea9 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -58,6 +58,13 @@ _zsh_highlight() # Store the previous command return code to restore it whatever happens. local ret=$? + # Remove all highlighting in isearch, so that only the underlining done by zsh itself remains. + # For details see FAQ entry 'Why does syntax highlighting not work while searching history?'. + if [[ $WIDGET == zle-isearch-update ]]; then + region_highlight=() + return $ret + fi + setopt localoptions warncreateglobal setopt localoptions noksharrays local REPLY # don't leak $REPLY into global scope @@ -258,6 +265,10 @@ _zsh_highlight_bind_widgets() # E.g. remove cursor imprint, don't highlight partial paths, ... widgets_to_bind+=(zle-line-finish) + # Always wrap special zle-isearch-update widget to be notified of updates in isearch. + # This is needed because we need to disable highlighting in that case. + widgets_to_bind+=(zle-isearch-update) + local cur_widget for cur_widget in $widgets_to_bind; do case $widgets[$cur_widget] in