akinomyoga / ble.sh

Bash Line Editor―a line editor written in pure Bash with syntax highlighting, auto suggestions, vim modes, etc. for Bash interactive sessions.
BSD 3-Clause "New" or "Revised" License
2.6k stars 82 forks source link

vi mode word extension from end of words doesn't work #328

Open bkerin opened 1 year ago

bkerin commented 1 year ago

GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu) [Linux Mint 20.3] ble.sh, version 0.4.0-devel4+0906fd9 (noarch) [git 2.25.1, GNU Make 4.3, GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.2.0)] bash-completion, version 2.10 (hash:b6da7f7edfc1c3c5196c86c81fb05fce96f83c03, 74550 bytes) (noarch) locale: LANG=en_US.UTF-8 terminal: TERM=xterm-256color wcwidth=12.1-west/15.0-2+ri, vte:6003 (65;6003;1)

If you put this on the command line:

 # foo bar

then position the cursor on the first o in foo, then type 'vliw', ble.sh fails to extend the visual selection to include the space as vi does.

I think the problem is an off-by-one in ble/keymap:vi/text-object/word.extend-forward (it's hidden by the regex except when the cursor ends on the last char of a wordafter direction indication). I think the fix is:

diff --git a/lib/keymap.vi.sh b/lib/keymap.vi.sh
old mode 100644
new mode 100755
index 25e9430..1219e64
--- a/lib/keymap.vi.sh
+++ b/lib/keymap.vi.sh
@@ -4478,9 +4478,9 @@ function ble/keymap:vi/text-object/word.extend-forward {
       [[ ${_ble_edit_str:end:1} == $'\n' ]] && ((end++))
     fi

-    [[ ${_ble_edit_str:end} =~ $rex_unit ]] || return 1
+    [[ ${_ble_edit_str:((end+1))} =~ $rex_unit ]] || return 1
     rematch=$BASH_REMATCH
-    ((end+=${#rematch}))
+    ((end+=${#rematch}+1))

     # Note: aw に対する正規表現では二重改行を読むが後退する。
     [[ $type == a* && $rematch == *$'\n\n' ]] && ((end--))
bkerin commented 1 year ago

ok trying again on the patch:

diff --git a/lib/keymap.vi.sh b/lib/keymap.vi.sh
old mode 100644
new mode 100755
index 25e9430..1219e64
--- a/lib/keymap.vi.sh
+++ b/lib/keymap.vi.sh
@@ -4478,9 +4478,9 @@ function ble/keymap:vi/text-object/word.extend-forward {
       [[ ${_ble_edit_str:end:1} == $'\n' ]] && ((end++))
     fi

-    [[ ${_ble_edit_str:end} =~ $rex_unit ]] || return 1
+    [[ ${_ble_edit_str:((end+1))} =~ $rex_unit ]] || return 1
     rematch=$BASH_REMATCH
-    ((end+=${#rematch}))
+    ((end+=${#rematch}+1))

     # Note: aw に対する正規表現では二重改行を読むが後退する。
     [[ $type == a* && $rematch == *$'\n\n' ]] && ((end--))
akinomyoga commented 1 year ago

Thank you! I'll take a look later.

By the way, you can re-edit a comment by the button on the top right corner:

image

This time, I edited your original comment by adding ```diff ... ```. (Note: The owner of the repository can also edit the comments of any people).