Compare commits

..

5 Commits

Author SHA1 Message Date
Eric Freese
146020d9b2 Merge pull request #454 from zsh-users/develop
v0.6.3
2019-06-24 09:13:46 -06:00
Eric Freese
0636a39b51 0.6.3 2019-06-24 09:10:42 -06:00
Eric Freese
6769c941ba Update changelog for v0.6.3 release 2019-06-24 09:10:42 -06:00
Eric Freese
371d6441c0 Merge pull request #453 from zsh-users/fixes/move-cursor-on-accept
Fix moving cursor to end of buffer when suggestion accepted
2019-06-24 07:16:35 -06:00
Eric Freese
78e4379711 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).
2019-06-23 12:37:08 -06:00
6 changed files with 17 additions and 61 deletions

View File

@@ -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)

View File

@@ -1 +1 @@
v0.6.2
v0.6.3

View File

@@ -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

View File

@@ -1,28 +0,0 @@
#--------------------------------------------------------------------#
# History Words Suggestion Strategy #
#--------------------------------------------------------------------#
# Suggests the most recent history word that matches the given
# prefix.
#
_zsh_autosuggest_strategy_historywords() {
# Reset options to defaults and enable LOCAL_OPTIONS
emulate -L zsh
# Enable globbing flags so that we can use (#m)
setopt EXTENDED_GLOB
local last_word="${${=1}[-1]}"
# Escape backslashes and all of the glob operators so we can use
# this string as a pattern to search the $history associative array.
# - (#m) globbing flag enables setting references for match data
# TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
local prefix="${last_word//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
# Get the first history word that matches. Concatenate it together with the
# prefix to form the full suggestion.
# - (r) subscript flag makes the pattern match on values
typeset -g suggestion="${1:0:-$#last_word}${historywords[(r)${prefix}?*]}"
}

View File

@@ -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 $@

View File

@@ -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
#
@@ -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 $@
@@ -611,34 +615,6 @@ _zsh_autosuggest_strategy_completion() {
}
}
#--------------------------------------------------------------------#
# History Words Suggestion Strategy #
#--------------------------------------------------------------------#
# Suggests the most recent history word that matches the given
# prefix.
#
_zsh_autosuggest_strategy_historywords() {
# Reset options to defaults and enable LOCAL_OPTIONS
emulate -L zsh
# Enable globbing flags so that we can use (#m)
setopt EXTENDED_GLOB
local last_word="${${=1}[-1]}"
# Escape backslashes and all of the glob operators so we can use
# this string as a pattern to search the $history associative array.
# - (#m) globbing flag enables setting references for match data
# TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
local prefix="${last_word//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
# Get the first history word that matches. Concatenate it together with the
# prefix to form the full suggestion.
# - (r) subscript flag makes the pattern match on values
typeset -g suggestion="${1:0:-$#last_word}${historywords[(r)${prefix}?*]}"
}
#--------------------------------------------------------------------#
# History Suggestion Strategy #
#--------------------------------------------------------------------#