From a91406590ead478522bdfa8cd330ec497cf810a3 Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Mon, 24 Oct 2016 10:00:58 +0200 Subject: [PATCH] =?UTF-8?q?Workaround=20for=20Zsh=20versions=20like=205.0.?= =?UTF-8?q?2=20=E2=80=93=20Ctrl-V=20to=20cancel=20search?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- history-search-multi-word | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/history-search-multi-word b/history-search-multi-word index 307cc07..4b0306a 100644 --- a/history-search-multi-word +++ b/history-search-multi-word @@ -175,6 +175,12 @@ _hsmw_delete_char() { _hsmw_simulate_widget } +_hsmw_cancel_accept() { + BUFFER="" + __hsmw_hcw_index=-1 + zle .accept-line +} + if [ "$__hsmw_hcw_call_count" -eq "1" ]; then # Make the hsmw keymap a copy of the current main bindkey -N hsmw emacs @@ -254,12 +260,21 @@ if [ "$__hsmw_hcw_call_count" -eq "1" ]; then zle -N "$pdown_widget" _hsmw_simulate_widget zle -N "$pup_widget" _hsmw_simulate_widget + # Add Ctrl-V binding to cancel search + # A workaround for Zsh versions like 5.0.2 + zle -N _hsmw_cancel_accept + bindkey -M hsmw "^V" _hsmw_cancel_accept + # Trap INT to manually interrupt Zle to work around a bug trap 'zle && zle .send-break' INT if zle .recursive-edit -K hsmw; then - BUFFER="${__hsmw_hcw_found[__hsmw_hcw_index]}" - CURSOR="${#BUFFER}" + if [[ "$__hsmw_hcw_index" -gt "0" ]]; then + BUFFER="${__hsmw_hcw_found[__hsmw_hcw_index]}" + CURSOR="${#BUFFER}" + else + BUFFER="" + fi else BUFFER="" fi