Переглянути джерело

Call original widget before moving cursor when accepting suggestion

The check on length of `$POSTDISPLAY` is in support of the test for
`vi-delete` on the last char of the buffer with `dl`.

Fixes issue #482.
pull/488/head
Eric Freese 4 роки тому
джерело
коміт
6ec95379fa
2 змінених файлів з 20 додано та 6 видалено
  1. +10
    -3
      src/widgets.zsh
  2. +10
    -3
      zsh-autosuggestions.zsh

+ 10
- 3
src/widgets.zsh Переглянути файл

@ -119,7 +119,7 @@ _zsh_autosuggest_suggest() {
# Accept the entire suggestion # Accept the entire suggestion
_zsh_autosuggest_accept() { _zsh_autosuggest_accept() {
local -i max_cursor_pos=$#BUFFER
local -i retval max_cursor_pos=$#BUFFER
# When vicmd keymap is active, the cursor can't move all the way # When vicmd keymap is active, the cursor can't move all the way
# to the end of the buffer # to the end of the buffer
@ -127,7 +127,9 @@ _zsh_autosuggest_accept() {
max_cursor_pos=$((max_cursor_pos - 1)) max_cursor_pos=$((max_cursor_pos - 1))
fi fi
if (( $CURSOR != $max_cursor_pos )); then
# If we're not in a valid state to accept a suggestion, just run the
# original widget and bail out
if (( $CURSOR != $max_cursor_pos || !$#POSTDISPLAY )); then
_zsh_autosuggest_invoke_original_widget $@ _zsh_autosuggest_invoke_original_widget $@
return return
fi fi
@ -139,6 +141,11 @@ _zsh_autosuggest_accept() {
# Remove the suggestion # Remove the suggestion
unset POSTDISPLAY unset POSTDISPLAY
# Run the original widget before manually moving the cursor so that the
# cursor movement doesn't make the widget do something unexpected
_zsh_autosuggest_invoke_original_widget $@
retval=$?
# Move the cursor to the end of the buffer # Move the cursor to the end of the buffer
if [[ "$KEYMAP" = "vicmd" ]]; then if [[ "$KEYMAP" = "vicmd" ]]; then
CURSOR=$(($#BUFFER - 1)) CURSOR=$(($#BUFFER - 1))
@ -146,7 +153,7 @@ _zsh_autosuggest_accept() {
CURSOR=$#BUFFER CURSOR=$#BUFFER
fi fi
_zsh_autosuggest_invoke_original_widget $@
return $retval
} }
# Accept the entire suggestion and execute it # Accept the entire suggestion and execute it

+ 10
- 3
zsh-autosuggestions.zsh Переглянути файл

@ -381,7 +381,7 @@ _zsh_autosuggest_suggest() {
# Accept the entire suggestion # Accept the entire suggestion
_zsh_autosuggest_accept() { _zsh_autosuggest_accept() {
local -i max_cursor_pos=$#BUFFER
local -i retval max_cursor_pos=$#BUFFER
# When vicmd keymap is active, the cursor can't move all the way # When vicmd keymap is active, the cursor can't move all the way
# to the end of the buffer # to the end of the buffer
@ -389,7 +389,9 @@ _zsh_autosuggest_accept() {
max_cursor_pos=$((max_cursor_pos - 1)) max_cursor_pos=$((max_cursor_pos - 1))
fi fi
if (( $CURSOR != $max_cursor_pos )); then
# If we're not in a valid state to accept a suggestion, just run the
# original widget and bail out
if (( $CURSOR != $max_cursor_pos || !$#POSTDISPLAY )); then
_zsh_autosuggest_invoke_original_widget $@ _zsh_autosuggest_invoke_original_widget $@
return return
fi fi
@ -401,6 +403,11 @@ _zsh_autosuggest_accept() {
# Remove the suggestion # Remove the suggestion
unset POSTDISPLAY unset POSTDISPLAY
# Run the original widget before manually moving the cursor so that the
# cursor movement doesn't make the widget do something unexpected
_zsh_autosuggest_invoke_original_widget $@
retval=$?
# Move the cursor to the end of the buffer # Move the cursor to the end of the buffer
if [[ "$KEYMAP" = "vicmd" ]]; then if [[ "$KEYMAP" = "vicmd" ]]; then
CURSOR=$(($#BUFFER - 1)) CURSOR=$(($#BUFFER - 1))
@ -408,7 +415,7 @@ _zsh_autosuggest_accept() {
CURSOR=$#BUFFER CURSOR=$#BUFFER
fi fi
_zsh_autosuggest_invoke_original_widget $@
return $retval
} }
# Accept the entire suggestion and execute it # Accept the entire suggestion and execute it

Завантаження…
Відмінити
Зберегти