From da5f0673b9a464c702f042a8a18d8ce2d08ac6e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atte=20Peltom=C3=A4ki?= Date: Wed, 11 Oct 2023 02:37:49 +0300 Subject: [PATCH] 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 --- README.md | 3 +++ zsh-history-substring-search.zsh | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/README.md b/README.md index aab5c17..aad153d 100644 --- a/README.md +++ b/README.md @@ -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 ------------------------------------------------------------------------------ diff --git a/zsh-history-substring-search.zsh b/zsh-history-substring-search.zsh index b0a0a8d..471cc9a 100644 --- a/zsh-history-substring-search.zsh +++ b/zsh-history-substring-search.zsh @@ -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 }