Merge pull request #453 from zsh-users/fixes/move-cursor-on-accept

Fix moving cursor to end of buffer when suggestion accepted
This commit is contained in:
Eric Freese 2019-06-24 07:16:35 -06:00 committed by GitHub
commit 371d6441c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

View File

@ -5,12 +5,13 @@ describe 'a zle widget' do
context 'when added to ZSH_AUTOSUGGEST_ACCEPT_WIDGETS' do context 'when added to ZSH_AUTOSUGGEST_ACCEPT_WIDGETS' do
let(:options) { ["ZSH_AUTOSUGGEST_ACCEPT_WIDGETS+=(#{widget})"] } let(:options) { ["ZSH_AUTOSUGGEST_ACCEPT_WIDGETS+=(#{widget})"] }
it 'accepts the suggestion when invoked' do it 'accepts the suggestion and moves the cursor to the end of the buffer when invoked' do
with_history('echo hello') do with_history('echo hello') do
session.send_string('e') session.send_string('e')
wait_for { session.content }.to eq('echo hello') wait_for { session.content }.to eq('echo hello')
session.send_keys('C-b') session.send_keys('C-b')
wait_for { session.content(esc_seqs: true) }.to eq('echo hello') wait_for { session.content(esc_seqs: true) }.to eq('echo hello')
wait_for { session.cursor }.to eq([10, 0])
end end
end end
end end

View File

@ -136,7 +136,11 @@ _zsh_autosuggest_accept() {
unset POSTDISPLAY unset POSTDISPLAY
# Move the cursor to the end of the buffer # Move the cursor to the end of the buffer
CURSOR=${max_cursor_pos} if [[ "$KEYMAP" = "vicmd" ]]; then
CURSOR=$(($#BUFFER - 1))
else
CURSOR=$#BUFFER
fi
fi fi
_zsh_autosuggest_invoke_original_widget $@ _zsh_autosuggest_invoke_original_widget $@

View File

@ -398,7 +398,11 @@ _zsh_autosuggest_accept() {
unset POSTDISPLAY unset POSTDISPLAY
# Move the cursor to the end of the buffer # Move the cursor to the end of the buffer
CURSOR=${max_cursor_pos} if [[ "$KEYMAP" = "vicmd" ]]; then
CURSOR=$(($#BUFFER - 1))
else
CURSOR=$#BUFFER
fi
fi fi
_zsh_autosuggest_invoke_original_widget $@ _zsh_autosuggest_invoke_original_widget $@