mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-12-28 15:14:51 +08:00
Fix #137
This commit is contained in:
parent
46d5fe174d
commit
15c5db898f
|
@ -32,8 +32,16 @@ _zsh_autosuggest_modify() {
|
||||||
|
|
||||||
# Accept the entire suggestion
|
# Accept the entire suggestion
|
||||||
_zsh_autosuggest_accept() {
|
_zsh_autosuggest_accept() {
|
||||||
|
local -i max_cursor_pos=$#BUFFER
|
||||||
|
|
||||||
|
# When vicmd keymap is active, the cursor can't move all the way
|
||||||
|
# to the end of the buffer
|
||||||
|
if [ "$KEYMAP" = "vicmd" ]; then
|
||||||
|
max_cursor_pos=$((max_cursor_pos - 1))
|
||||||
|
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 -eq $#BUFFER ]; then
|
if [ $CURSOR -eq $max_cursor_pos ]; then
|
||||||
# Add the suggestion to the buffer
|
# Add the suggestion to the buffer
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
BUFFER="$BUFFER$POSTDISPLAY"
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,56 @@ testCursorNotAtEnd() {
|
||||||
"$POSTDISPLAY"
|
"$POSTDISPLAY"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testViCursorAtEnd() {
|
||||||
|
BUFFER='echo'
|
||||||
|
POSTDISPLAY=' hello'
|
||||||
|
CURSOR=3
|
||||||
|
KEYMAP='vicmd'
|
||||||
|
|
||||||
|
stub _zsh_autosuggest_invoke_original_widget
|
||||||
|
|
||||||
|
_zsh_autosuggest_accept 'original-widget'
|
||||||
|
|
||||||
|
assertTrue \
|
||||||
|
'original widget not invoked' \
|
||||||
|
'stub_called _zsh_autosuggest_invoke_original_widget'
|
||||||
|
|
||||||
|
assertEquals \
|
||||||
|
'BUFFER was not modified' \
|
||||||
|
'echo hello' \
|
||||||
|
"$BUFFER"
|
||||||
|
|
||||||
|
assertEquals \
|
||||||
|
'POSTDISPLAY was not cleared' \
|
||||||
|
'' \
|
||||||
|
"$POSTDISPLAY"
|
||||||
|
}
|
||||||
|
|
||||||
|
testViCursorNotAtEnd() {
|
||||||
|
BUFFER='echo'
|
||||||
|
POSTDISPLAY=' hello'
|
||||||
|
CURSOR=2
|
||||||
|
KEYMAP='vicmd'
|
||||||
|
|
||||||
|
stub _zsh_autosuggest_invoke_original_widget
|
||||||
|
|
||||||
|
_zsh_autosuggest_accept 'original-widget'
|
||||||
|
|
||||||
|
assertTrue \
|
||||||
|
'original widget not invoked' \
|
||||||
|
'stub_called _zsh_autosuggest_invoke_original_widget'
|
||||||
|
|
||||||
|
assertEquals \
|
||||||
|
'BUFFER was modified' \
|
||||||
|
'echo' \
|
||||||
|
"$BUFFER"
|
||||||
|
|
||||||
|
assertEquals \
|
||||||
|
'POSTDISPLAY was modified' \
|
||||||
|
' hello' \
|
||||||
|
"$POSTDISPLAY"
|
||||||
|
}
|
||||||
|
|
||||||
testWidget() {
|
testWidget() {
|
||||||
stub _zsh_autosuggest_highlight_reset
|
stub _zsh_autosuggest_highlight_reset
|
||||||
stub _zsh_autosuggest_accept
|
stub _zsh_autosuggest_accept
|
||||||
|
|
|
@ -245,8 +245,16 @@ _zsh_autosuggest_modify() {
|
||||||
|
|
||||||
# Accept the entire suggestion
|
# Accept the entire suggestion
|
||||||
_zsh_autosuggest_accept() {
|
_zsh_autosuggest_accept() {
|
||||||
|
local -i max_cursor_pos=$#BUFFER
|
||||||
|
|
||||||
|
# When vicmd keymap is active, the cursor can't move all the way
|
||||||
|
# to the end of the buffer
|
||||||
|
if [ "$KEYMAP" = "vicmd" ]; then
|
||||||
|
max_cursor_pos=$((max_cursor_pos - 1))
|
||||||
|
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 -eq $#BUFFER ]; then
|
if [ $CURSOR -eq $max_cursor_pos ]; then
|
||||||
# Add the suggestion to the buffer
|
# Add the suggestion to the buffer
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
BUFFER="$BUFFER$POSTDISPLAY"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user