fix search match highlight with latest z-sy-h

Search highlight is cleared after a timeout, which is one second by default.
Timeout period can be changed by setting an environment variable; example below
for setting one minute timeout.

  HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_TIMEOUT=60

Fixes #131
This commit is contained in:
Atte Peltomäki 2023-10-11 02:37:49 +03:00 committed by Koston-0xDEADBEEF
parent 400e58a87f
commit da5f0673b9
2 changed files with 20 additions and 0 deletions

View file

@ -161,6 +161,9 @@ default values.
receive globally unique search results only once, then use this
configuration variable, or use `setopt HIST_IGNORE_ALL_DUPS`.
* `HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_TIMEOUT` is a global variable that
defines a timeout in seconds for clearing the search highlight.
History
------------------------------------------------------------------------------

View file

@ -408,6 +408,23 @@ _history-substring-search-end() {
# zle -R "mn: "$_history_substring_search_match_index" m#: "${#_history_substring_search_matches}
# read -k -t 200 && zle -U $REPLY
#
# When this function returns, z-sy-h runs its line-pre-redraw hook. It has no
# logic for determining highlight priority, when two different memo= marked
# region highlights overlap; instead, it always prioritises itself. Below is
# a workaround for dealing with it.
#
if [[ $_history_substring_search_zsh_5_9 -eq 1 ]]; then
zle -R
#
# After line redraw with desired highlight, wait for timeout or user input
# before removing search highlight and exiting. This ensures no highlights
# are left lingering after search is finished.
#
read -k -t ${HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_TIMEOUT:-1} && zle -U $REPLY
region_highlight=( "${(@)region_highlight:#*${highlight_memo}*}" )
fi
# Exit successfully from the history-substring-search-* widgets.
return 0
}