File tree Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -119,15 +119,17 @@ _zsh_autosuggest_suggest() {
119
119
120
120
# Accept the entire suggestion
121
121
_zsh_autosuggest_accept () {
122
- local -i max_cursor_pos=$# BUFFER
122
+ local -i retval max_cursor_pos=$# BUFFER
123
123
124
124
# When vicmd keymap is active, the cursor can't move all the way
125
125
# to the end of the buffer
126
126
if [[ " $KEYMAP " = " vicmd" ]]; then
127
127
max_cursor_pos=$(( max_cursor_pos - 1 ))
128
128
fi
129
129
130
- if (( $CURSOR != $max_cursor_pos )) ; then
130
+ # If we're not in a valid state to accept a suggestion, just run the
131
+ # original widget and bail out
132
+ if (( $CURSOR != $max_cursor_pos || ! $# POSTDISPLAY )) ; then
131
133
_zsh_autosuggest_invoke_original_widget $@
132
134
return
133
135
fi
@@ -139,14 +141,19 @@ _zsh_autosuggest_accept() {
139
141
# Remove the suggestion
140
142
unset POSTDISPLAY
141
143
144
+ # Run the original widget before manually moving the cursor so that the
145
+ # cursor movement doesn't make the widget do something unexpected
146
+ _zsh_autosuggest_invoke_original_widget $@
147
+ retval=$?
148
+
142
149
# Move the cursor to the end of the buffer
143
150
if [[ " $KEYMAP " = " vicmd" ]]; then
144
151
CURSOR=$(( $# BUFFER - 1 ))
145
152
else
146
153
CURSOR=$# BUFFER
147
154
fi
148
155
149
- _zsh_autosuggest_invoke_original_widget $@
156
+ return $retval
150
157
}
151
158
152
159
# Accept the entire suggestion and execute it
Original file line number Diff line number Diff line change @@ -381,15 +381,17 @@ _zsh_autosuggest_suggest() {
381
381
382
382
# Accept the entire suggestion
383
383
_zsh_autosuggest_accept () {
384
- local -i max_cursor_pos=$# BUFFER
384
+ local -i retval max_cursor_pos=$# BUFFER
385
385
386
386
# When vicmd keymap is active, the cursor can't move all the way
387
387
# to the end of the buffer
388
388
if [[ " $KEYMAP " = " vicmd" ]]; then
389
389
max_cursor_pos=$(( max_cursor_pos - 1 ))
390
390
fi
391
391
392
- if (( $CURSOR != $max_cursor_pos )) ; then
392
+ # If we're not in a valid state to accept a suggestion, just run the
393
+ # original widget and bail out
394
+ if (( $CURSOR != $max_cursor_pos || ! $# POSTDISPLAY )) ; then
393
395
_zsh_autosuggest_invoke_original_widget $@
394
396
return
395
397
fi
@@ -401,14 +403,19 @@ _zsh_autosuggest_accept() {
401
403
# Remove the suggestion
402
404
unset POSTDISPLAY
403
405
406
+ # Run the original widget before manually moving the cursor so that the
407
+ # cursor movement doesn't make the widget do something unexpected
408
+ _zsh_autosuggest_invoke_original_widget $@
409
+ retval=$?
410
+
404
411
# Move the cursor to the end of the buffer
405
412
if [[ " $KEYMAP " = " vicmd" ]]; then
406
413
CURSOR=$(( $# BUFFER - 1 ))
407
414
else
408
415
CURSOR=$# BUFFER
409
416
fi
410
417
411
- _zsh_autosuggest_invoke_original_widget $@
418
+ return $retval
412
419
}
413
420
414
421
# Accept the entire suggestion and execute it
You can’t perform that action at this time.
0 commit comments