Skip to content

Commit

Permalink
fix search match highlight with latest z-sy-h
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Koston-0xDEADBEEF committed Nov 8, 2023
1 parent 400e58a commit da5f067
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -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
------------------------------------------------------------------------------
Expand Down
17 changes: 17 additions & 0 deletions zsh-history-substring-search.zsh
Expand Up @@ -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
}
Expand Down

0 comments on commit da5f067

Please sign in to comment.