From b9345ebcebd706e5e9cf71728bc0d4af5b0bb055 Mon Sep 17 00:00:00 2001 From: Arnaud Venturi Date: Fri, 4 May 2018 18:04:19 +0200 Subject: [PATCH] Using a separate variable instead of rolling back CURSOR to its initial value --- src/widgets.zsh | 12 ++++-------- zsh-autosuggestions.zsh | 12 ++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/widgets.zsh b/src/widgets.zsh index 190ddce..43cd974 100644 --- a/src/widgets.zsh +++ b/src/widgets.zsh @@ -166,13 +166,14 @@ _zsh_autosuggest_partial_accept() { # In vicmd keymap, the cursor is placed on the current character # instead of after it. We increment it by 1 to keep the following logic - # working even in thi case. + # working even in this case. + CURSOR_POS=$CURSOR if [ $KEYMAP = 'vicmd' ]; then - (( CURSOR++ )) + (( CURSOR_POS++ )) fi # If we've moved past the end of the original buffer - if (( $CURSOR > $#original_buffer )); then + if (( $CURSOR_POS > $#original_buffer )); then # Set POSTDISPLAY to text right of the cursor POSTDISPLAY="$RBUFFER" @@ -183,11 +184,6 @@ _zsh_autosuggest_partial_accept() { BUFFER="$original_buffer" fi - # Restore CURSOR - if [ $KEYMAP = 'vicmd' ]; then - (( CURSOR-- )) - fi - return $retval } diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 931598f..96996dc 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -444,13 +444,14 @@ _zsh_autosuggest_partial_accept() { # In vicmd keymap, the cursor is placed on the current character # instead of after it. We increment it by 1 to keep the following logic - # working even in thi case. + # working even in this case. + CURSOR_POS=$CURSOR if [ $KEYMAP = 'vicmd' ]; then - (( CURSOR++ )) + (( CURSOR_POS++ )) fi # If we've moved past the end of the original buffer - if (( $CURSOR > $#original_buffer )); then + if (( $CURSOR_POS > $#original_buffer )); then # Set POSTDISPLAY to text right of the cursor POSTDISPLAY="$RBUFFER" @@ -461,11 +462,6 @@ _zsh_autosuggest_partial_accept() { BUFFER="$original_buffer" fi - # Restore CURSOR - if [ $KEYMAP = 'vicmd' ]; then - (( CURSOR-- )) - fi - return $retval }