mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-11-18 09:51:06 +01:00
cleanup: Switch to guard clause in accept widget handler
This commit is contained in:
parent
5217ed5269
commit
54d7a9a84c
2 changed files with 28 additions and 22 deletions
|
@ -127,20 +127,23 @@ _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
|
||||||
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
# Only accept if the cursor is at the end of the buffer
|
# Only accept if the cursor is at the end of the buffer
|
||||||
if (( $CURSOR == $max_cursor_pos )); then
|
# Add the suggestion to the buffer
|
||||||
# Add the suggestion to the buffer
|
BUFFER="$BUFFER$POSTDISPLAY"
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
|
||||||
|
|
||||||
# Remove the suggestion
|
# Remove the suggestion
|
||||||
unset POSTDISPLAY
|
unset POSTDISPLAY
|
||||||
|
|
||||||
# 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))
|
||||||
else
|
else
|
||||||
CURSOR=$#BUFFER
|
CURSOR=$#BUFFER
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
|
|
|
@ -389,20 +389,23 @@ _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
|
||||||
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
# Only accept if the cursor is at the end of the buffer
|
# Only accept if the cursor is at the end of the buffer
|
||||||
if (( $CURSOR == $max_cursor_pos )); then
|
# Add the suggestion to the buffer
|
||||||
# Add the suggestion to the buffer
|
BUFFER="$BUFFER$POSTDISPLAY"
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
|
||||||
|
|
||||||
# Remove the suggestion
|
# Remove the suggestion
|
||||||
unset POSTDISPLAY
|
unset POSTDISPLAY
|
||||||
|
|
||||||
# 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))
|
||||||
else
|
else
|
||||||
CURSOR=$#BUFFER
|
CURSOR=$#BUFFER
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
|
|
Loading…
Reference in a new issue