From 676aebdf448569eab83f208665b6e21731d1d6be Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Mon, 14 May 2018 10:25:55 -0600 Subject: [PATCH 1/4] Fix deleting last character in vi mode (#302) Typing `d` and then `l` runs `vi-delete` and then `vi-forward-char`. However, by default, `vi-forward-char` is configured to accept the suggestion. So in that case, the suggestion was being accepted and the cursor set to the end of the buffer before the deletion was run. The reason the user doesn't see the suggestion accepted is that `vi-delete` doesn't finish until the movement widget is run, so we're already inside of a `modify` when `accept` is called. `modify` unsets `POSTDISPLAY` before calling the original widget so when we get to the accept function, `POSTDISPLAY` is empty and thus accepting the suggestion is a no-op. The fix is to make sure we reset the cursor to the correct place before running the original widget. We skip the test for versions of zsh below 5.0.8 since there was a bug in earlier versions where deleting the last char did not work. See http://www.zsh.org/mla/workers/2014/msg01316.html --- spec/integrations/vi_mode_spec.rb | 15 ++++++++++++++- src/widgets.zsh | 2 +- zsh-autosuggestions.zsh | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/spec/integrations/vi_mode_spec.rb b/spec/integrations/vi_mode_spec.rb index cf471b5..0a295c2 100644 --- a/spec/integrations/vi_mode_spec.rb +++ b/spec/integrations/vi_mode_spec.rb @@ -63,5 +63,18 @@ describe 'when using vi mode' do end end end -end + describe '`vi-delete`' do + it 'should be able to remove the last character in the buffer' do + skip 'deleting last char did not work below zsh version 5.0.8' if session.zsh_version < Gem::Version.new('5.0.8') + + session. + send_string('echo foo'). + send_keys('escape'). + send_keys('d'). + send_keys('l') + + wait_for { session.content }.to eq('echo fo') + end + end +end diff --git a/src/widgets.zsh b/src/widgets.zsh index 450ed3c..2d8be5e 100644 --- a/src/widgets.zsh +++ b/src/widgets.zsh @@ -136,7 +136,7 @@ _zsh_autosuggest_accept() { unset POSTDISPLAY # Move the cursor to the end of the buffer - CURSOR=${#BUFFER} + CURSOR=${max_cursor_pos} fi _zsh_autosuggest_invoke_original_widget $@ diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index cd68f69..8384e7c 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -398,7 +398,7 @@ _zsh_autosuggest_accept() { unset POSTDISPLAY # Move the cursor to the end of the buffer - CURSOR=${#BUFFER} + CURSOR=${max_cursor_pos} fi _zsh_autosuggest_invoke_original_widget $@ From 66a6de3fb52a587970be530bf809a733d8fbb040 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Sat, 22 Jun 2019 16:52:42 -0600 Subject: [PATCH 2/4] Update changelog for v0.6.2 release --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b850cb..6d4d547 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 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) + ## v0.6.1 - Fixed bug occurring when `_complete` had been aliased (#443) From cdf6be4f0617c88ccf7dff5ef229ae5fb710547e Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Sat, 22 Jun 2019 16:54:03 -0600 Subject: [PATCH 3/4] Update readme description to reference new completion strategy --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1dac45c..0e47f9e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ _[Fish](http://fishshell.com/)-like fast/unobtrusive autosuggestions for zsh._ -It suggests commands as you type. +It suggests commands as you type based on history and completions. Requirements: Zsh v4.3.11 or later From cb52adf4294141ee705f5804d4a246d86e46e3f0 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Sat, 22 Jun 2019 16:54:32 -0600 Subject: [PATCH 4/4] v0.6.2 --- VERSION | 2 +- zsh-autosuggestions.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 1490961..45964c6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v0.6.1 +v0.6.2 diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 8384e7c..dc0af63 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.1 +# v0.6.2 # Copyright (c) 2013 Thiago de Arruda # Copyright (c) 2016-2019 Eric Freese #