diff --git a/.config/kak/autoload/search-highlight.kak b/.config/kak/autoload/search-highlight.kak index a4b6c9e2..e6b684cb 100644 --- a/.config/kak/autoload/search-highlight.kak +++ b/.config/kak/autoload/search-highlight.kak @@ -35,21 +35,32 @@ provide-module search-highlight %— try %{ %opt{search_highlight_status} } catch %{ - map window prompt ': set-option window search_highlight_quit true' - # if not, add the highlighter + # if the user escapes search, we should immediately clear the highlight + # in normal mode so we set the flag before escaping + # map window prompt ': set-option window search_highlight_quit true' + # if not already enabled, add the highlighter add-highlighter window/search-highlight dynregex '%reg{/}' %exp{0:%opt{search_highlight_face}} # update status tracker set-option window search_highlight_status 'search-highlight-on' # register hook to clear highlighter after leaving search hook -once -group search-highlight window NormalIdle .* %{ + # check if user escaped search try %{ %opt{search_highlight_quit} + # if so, clear immediately search-highlight-clear } catch %{ - map window normal ': search-highlight-clear' + # otherwise, we clear on escape + hook -once -group search-highlight window NormalKey %{ + search-highlight-clear + } } + # clear the prompt mapping so it doesn't conflict with + # other prompt types unmap window prompt + # reset the quit-early flag + set-option window search_highlight_quit false } } }