mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-11-18 09:51:06 +01:00
Merge pull request #488 from zsh-users/fixes/run-orig-before-move-cursor
Call original widget before moving cursor when accepting suggestion
This commit is contained in:
commit
0d2c9de2ea
2 changed files with 52 additions and 32 deletions
|
@ -56,7 +56,7 @@ _zsh_autosuggest_modify() {
|
||||||
emulate -L zsh
|
emulate -L zsh
|
||||||
|
|
||||||
# Don't fetch a new suggestion if there's more input to be read immediately
|
# Don't fetch a new suggestion if there's more input to be read immediately
|
||||||
if (( $PENDING > 0 )) || (( $KEYS_QUEUED_COUNT > 0 )); then
|
if (( $PENDING > 0 || $KEYS_QUEUED_COUNT > 0 )); then
|
||||||
POSTDISPLAY="$orig_postdisplay"
|
POSTDISPLAY="$orig_postdisplay"
|
||||||
return $retval
|
return $retval
|
||||||
fi
|
fi
|
||||||
|
@ -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,23 +127,33 @@ _zsh_autosuggest_accept() {
|
||||||
max_cursor_pos=$((max_cursor_pos - 1))
|
max_cursor_pos=$((max_cursor_pos - 1))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Only accept if the cursor is at the end of the buffer
|
# If we're not in a valid state to accept a suggestion, just run the
|
||||||
if [[ $CURSOR = $max_cursor_pos ]]; then
|
# original widget and bail out
|
||||||
# Add the suggestion to the buffer
|
if (( $CURSOR != $max_cursor_pos || !$#POSTDISPLAY )); then
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
|
return
|
||||||
# Remove the suggestion
|
|
||||||
unset POSTDISPLAY
|
|
||||||
|
|
||||||
# Move the cursor to the end of the buffer
|
|
||||||
if [[ "$KEYMAP" = "vicmd" ]]; then
|
|
||||||
CURSOR=$(($#BUFFER - 1))
|
|
||||||
else
|
|
||||||
CURSOR=$#BUFFER
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Only accept if the cursor is at the end of the buffer
|
||||||
|
# Add the suggestion to the buffer
|
||||||
|
BUFFER="$BUFFER$POSTDISPLAY"
|
||||||
|
|
||||||
|
# Remove the suggestion
|
||||||
|
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 $@
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
|
retval=$?
|
||||||
|
|
||||||
|
# Move the cursor to the end of the buffer
|
||||||
|
if [[ "$KEYMAP" = "vicmd" ]]; then
|
||||||
|
CURSOR=$(($#BUFFER - 1))
|
||||||
|
else
|
||||||
|
CURSOR=$#BUFFER
|
||||||
|
fi
|
||||||
|
|
||||||
|
return $retval
|
||||||
}
|
}
|
||||||
|
|
||||||
# Accept the entire suggestion and execute it
|
# Accept the entire suggestion and execute it
|
||||||
|
|
|
@ -318,7 +318,7 @@ _zsh_autosuggest_modify() {
|
||||||
emulate -L zsh
|
emulate -L zsh
|
||||||
|
|
||||||
# Don't fetch a new suggestion if there's more input to be read immediately
|
# Don't fetch a new suggestion if there's more input to be read immediately
|
||||||
if (( $PENDING > 0 )) || (( $KEYS_QUEUED_COUNT > 0 )); then
|
if (( $PENDING > 0 || $KEYS_QUEUED_COUNT > 0 )); then
|
||||||
POSTDISPLAY="$orig_postdisplay"
|
POSTDISPLAY="$orig_postdisplay"
|
||||||
return $retval
|
return $retval
|
||||||
fi
|
fi
|
||||||
|
@ -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,23 +389,33 @@ _zsh_autosuggest_accept() {
|
||||||
max_cursor_pos=$((max_cursor_pos - 1))
|
max_cursor_pos=$((max_cursor_pos - 1))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Only accept if the cursor is at the end of the buffer
|
# If we're not in a valid state to accept a suggestion, just run the
|
||||||
if [[ $CURSOR = $max_cursor_pos ]]; then
|
# original widget and bail out
|
||||||
# Add the suggestion to the buffer
|
if (( $CURSOR != $max_cursor_pos || !$#POSTDISPLAY )); then
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
|
return
|
||||||
# Remove the suggestion
|
|
||||||
unset POSTDISPLAY
|
|
||||||
|
|
||||||
# Move the cursor to the end of the buffer
|
|
||||||
if [[ "$KEYMAP" = "vicmd" ]]; then
|
|
||||||
CURSOR=$(($#BUFFER - 1))
|
|
||||||
else
|
|
||||||
CURSOR=$#BUFFER
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Only accept if the cursor is at the end of the buffer
|
||||||
|
# Add the suggestion to the buffer
|
||||||
|
BUFFER="$BUFFER$POSTDISPLAY"
|
||||||
|
|
||||||
|
# Remove the suggestion
|
||||||
|
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 $@
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
|
retval=$?
|
||||||
|
|
||||||
|
# Move the cursor to the end of the buffer
|
||||||
|
if [[ "$KEYMAP" = "vicmd" ]]; then
|
||||||
|
CURSOR=$(($#BUFFER - 1))
|
||||||
|
else
|
||||||
|
CURSOR=$#BUFFER
|
||||||
|
fi
|
||||||
|
|
||||||
|
return $retval
|
||||||
}
|
}
|
||||||
|
|
||||||
# Accept the entire suggestion and execute it
|
# Accept the entire suggestion and execute it
|
||||||
|
|
Loading…
Reference in a new issue