Skip to content

Commit 371d644

Browse files
authored
Merge pull request #453 from zsh-users/fixes/move-cursor-on-accept
Fix moving cursor to end of buffer when suggestion accepted
2 parents c806055 + 78e4379 commit 371d644

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

spec/options/widget_lists_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
context 'when added to ZSH_AUTOSUGGEST_ACCEPT_WIDGETS' do
66
let(:options) { ["ZSH_AUTOSUGGEST_ACCEPT_WIDGETS+=(#{widget})"] }
77

8-
it 'accepts the suggestion when invoked' do
8+
it 'accepts the suggestion and moves the cursor to the end of the buffer when invoked' do
99
with_history('echo hello') do
1010
session.send_string('e')
1111
wait_for { session.content }.to eq('echo hello')
1212
session.send_keys('C-b')
1313
wait_for { session.content(esc_seqs: true) }.to eq('echo hello')
14+
wait_for { session.cursor }.to eq([10, 0])
1415
end
1516
end
1617
end

src/widgets.zsh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ _zsh_autosuggest_accept() {
136136
unset POSTDISPLAY
137137

138138
# Move the cursor to the end of the buffer
139-
CURSOR=${max_cursor_pos}
139+
if [[ "$KEYMAP" = "vicmd" ]]; then
140+
CURSOR=$(($#BUFFER - 1))
141+
else
142+
CURSOR=$#BUFFER
143+
fi
140144
fi
141145

142146
_zsh_autosuggest_invoke_original_widget $@

zsh-autosuggestions.zsh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,11 @@ _zsh_autosuggest_accept() {
398398
unset POSTDISPLAY
399399

400400
# Move the cursor to the end of the buffer
401-
CURSOR=${max_cursor_pos}
401+
if [[ "$KEYMAP" = "vicmd" ]]; then
402+
CURSOR=$(($#BUFFER - 1))
403+
else
404+
CURSOR=$#BUFFER
405+
fi
402406
fi
403407

404408
_zsh_autosuggest_invoke_original_widget $@

0 commit comments

Comments
 (0)