mirror of
https://github.com/zdharma-continuum/history-search-multi-word
synced 2024-11-22 03:13:09 +00:00
Clean "copy" of the same widget to override itself - for autosuggestions
This commit is contained in:
parent
4b76fc0860
commit
96a4d3f45b
1 changed files with 21 additions and 5 deletions
|
@ -9,8 +9,6 @@ typeset -g __hsmw_hcw_index
|
|||
typeset -g __hsmw_hcw_widget_name __hsmw_hcw_restart __hsmw_hcw_call_count
|
||||
typeset -gaU __hsmw_hcw_found
|
||||
|
||||
(( __hsmw_hcw_call_count ++ ))
|
||||
|
||||
_zhcw_main() {
|
||||
# First call or restart?
|
||||
if [[ "$__hsmw_hcw_call_count" -le 1 || "$__hsmw_hcw_restart" = "1" ]]; then
|
||||
|
@ -90,6 +88,14 @@ _zhcw_main() {
|
|||
fi
|
||||
}
|
||||
|
||||
(( __hsmw_hcw_call_count ++ ))
|
||||
_zhcw_main
|
||||
|
||||
_zhcw_simulate_widget() {
|
||||
(( __hsmw_hcw_call_count ++ ))
|
||||
_zhcw_main
|
||||
}
|
||||
|
||||
_zhcw_self_insert() {
|
||||
LBUFFER+="${KEYS[-1]}"
|
||||
__hsmw_hcw_restart="1"
|
||||
|
@ -108,8 +114,6 @@ _zhcw_delete_char() {
|
|||
_zhcw_main
|
||||
}
|
||||
|
||||
_zhcw_main
|
||||
|
||||
if [ "$__hsmw_hcw_call_count" -eq "1" ]; then
|
||||
# Make the zhcw keymap a copy of the current main
|
||||
bindkey -N zhcw emacs
|
||||
|
@ -133,22 +137,34 @@ if [ "$__hsmw_hcw_call_count" -eq "1" ]; then
|
|||
zle -A self-insert saved-self-insert
|
||||
zle -A backward-delete-char saved-backward-delete-char
|
||||
zle -A delete-char saved-delete-char
|
||||
|
||||
zle -N self-insert _zhcw_self_insert
|
||||
zle -N backward-delete-char _zhcw_backward_delete_char
|
||||
zle -N delete-char _zhcw_delete_char
|
||||
|
||||
# Override ourselves with what we actually are
|
||||
# because zsh-autosuggestions change us
|
||||
zle -A "$down_widget" saved-"$down_widget"
|
||||
zle -A "$up_widget" saved-"$up_widget"
|
||||
zle -N "$down_widget" _zhcw_simulate_widget
|
||||
zle -N "$up_widget" _zhcw_simulate_widget
|
||||
|
||||
if zle .recursive-edit -K zhcw; then
|
||||
BUFFER="${__hsmw_hcw_found[__hsmw_hcw_index]}"
|
||||
CURSOR="${#BUFFER}"
|
||||
fi
|
||||
POSTDISPLAY=""
|
||||
|
||||
# Restore self-insert, backward-delete-char, delete-char
|
||||
zle -A saved-self-insert self-insert
|
||||
zle -A saved-backward-delete-char backward-delete-char
|
||||
zle -A saved-delete-char delete-char
|
||||
zle -D saved-self-insert saved-backward-delete-char saved-delete-char
|
||||
|
||||
# Restore ourselves
|
||||
zle -A saved-"$down_widget" "$down_widget"
|
||||
zle -A saved-"$up_widget" "$up_widget"
|
||||
zle -D saved-"$down_widget" saved-"$up_widget"
|
||||
|
||||
# Full reinitialisation at next call
|
||||
__hsmw_hcw_call_count="0"
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue