From 78e4379711433e97192fdde51a3c5af9d29713e7 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Sun, 23 Jun 2019 12:37:08 -0600 Subject: [PATCH 1/3] Fix moving cursor to end of buffer when suggestion accepted $max_cursor_pos in this case was not the correct value to use. It was calculated based on the old length of the $BUFFER. After the suggestion is accepted, we need to recalculate the new max cursor length and use it to set the $CURSOR. Fixes issue #452. Follow-up to issue #302 (PR #450). --- spec/options/widget_lists_spec.rb | 3 ++- src/widgets.zsh | 6 +++++- zsh-autosuggestions.zsh | 6 +++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/spec/options/widget_lists_spec.rb b/spec/options/widget_lists_spec.rb index db3612f..421b84e 100644 --- a/spec/options/widget_lists_spec.rb +++ b/spec/options/widget_lists_spec.rb @@ -5,12 +5,13 @@ describe 'a zle widget' do context 'when added to ZSH_AUTOSUGGEST_ACCEPT_WIDGETS' do 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 session.send_string('e') wait_for { session.content }.to eq('echo hello') session.send_keys('C-b') wait_for { session.content(esc_seqs: true) }.to eq('echo hello') + wait_for { session.cursor }.to eq([10, 0]) end end end diff --git a/src/widgets.zsh b/src/widgets.zsh index 2d8be5e..242d502 100644 --- a/src/widgets.zsh +++ b/src/widgets.zsh @@ -136,7 +136,11 @@ _zsh_autosuggest_accept() { unset POSTDISPLAY # 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 _zsh_autosuggest_invoke_original_widget $@ diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 21a1a1c..a287c82 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -398,7 +398,11 @@ _zsh_autosuggest_accept() { unset POSTDISPLAY # 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 _zsh_autosuggest_invoke_original_widget $@ From 6769c941ba38fbc6525ae085322d7dbe41d44dc1 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Mon, 24 Jun 2019 09:10:02 -0600 Subject: [PATCH 2/3] Update changelog for v0.6.3 release --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d4d547..37bf991 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## v0.6.3 +- Fixed bug moving cursor to end of buffer after accepting suggestion (#453) + ## v0.6.2 - Fixed bug deleting the last character in the buffer in vi mode (#450) - Degrade gracefully when user doesn't have `zsh/system` module installed (#447) From 0636a39b5170988a45590869b2f1d79d12065763 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Mon, 24 Jun 2019 09:10:20 -0600 Subject: [PATCH 3/3] 0.6.3 --- VERSION | 2 +- zsh-autosuggestions.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 45964c6..e4c57af 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v0.6.2 +v0.6.3 diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index a287c82..872b647 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -1,6 +1,6 @@ # Fish-like fast/unobtrusive autosuggestions for zsh. # https://github.com/zsh-users/zsh-autosuggestions -# v0.6.2 +# v0.6.3 # Copyright (c) 2013 Thiago de Arruda # Copyright (c) 2016-2019 Eric Freese #