Fix vi-mode partial-accept

Issue #188. PR #324.

Thanks to @toadjaune and @IngoHeimbach.
This commit is contained in:
Eric Freese
2018-05-14 10:59:08 -06:00
parent 42f5a06f7f
commit 393f7b8bb9
4 changed files with 70 additions and 8 deletions

View File

@@ -85,6 +85,8 @@ ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
vi-forward-word-end
vi-forward-blank-word
vi-forward-blank-word-end
vi-find-next-char
vi-find-next-char-skip
)
# Widgets that should be ignored (globbing supported but must be escaped)
@@ -431,7 +433,7 @@ _zsh_autosuggest_execute() {
# Partially accept the suggestion
_zsh_autosuggest_partial_accept() {
local -i retval
local -i retval cursor_loc
# Save the contents of the buffer so we can restore later if needed
local original_buffer="$BUFFER"
@@ -443,13 +445,19 @@ _zsh_autosuggest_partial_accept() {
_zsh_autosuggest_invoke_original_widget $@
retval=$?
# Normalize cursor location across vi/emacs modes
cursor_loc=$CURSOR
if [[ "$KEYMAP" = "vicmd" ]]; then
cursor_loc=$((cursor_loc + 1))
fi
# If we've moved past the end of the original buffer
if (( $CURSOR > $#original_buffer )); then
if (( $cursor_loc > $#original_buffer )); then
# Set POSTDISPLAY to text right of the cursor
POSTDISPLAY="$RBUFFER"
POSTDISPLAY="${BUFFER[$(($cursor_loc + 1)),$#BUFFER]}"
# Clip the buffer at the cursor
BUFFER="$LBUFFER"
BUFFER="${BUFFER[1,$cursor_loc]}"
else
# Restore the original buffer
BUFFER="$original_buffer"