Subject: Re: [vi-mode] widgets for case manipulation: `gU` and `U` in visual mode
From: Oliver Kiddle <[email-masked]>
To: [email-masked]
Cc: Filipe Silva <[email-masked]>
Date: Wed, 22 Jun 2016 21:57:22 +0200
List-Id: Zsh Workers List <zsh-workers.zsh.org>

Bart wrote:
>
> I think the "surround" widget and/or select-{bracketed.quoted} have the
> same problem:

> - end up with c(ab)de on the line, expected (ab)cde

Yes. Thanks. This should correct that and the ksharrays point you also
made.

Oliver

diff --git a/Functions/Zle/select-bracketed b/Functions/Zle/select-bracketed
index 00f51be..d467bb8 100644
--- a/Functions/Zle/select-bracketed
+++ b/Functions/Zle/select-bracketed
@@ -12,6 +12,8 @@
 #	done
 #     done
 
+setopt localoptions noksharrays
+
 local style=${${1:-$KEYS}[1]} matching="(){}[]<>bbBB"
 local -i find=${NUMERIC:-1} idx=${matching[(I)[${${1:-$KEYS}[2]}]]}%9
 (( idx )) || return 1 # no corresponding closing bracket
diff --git a/Functions/Zle/surround b/Functions/Zle/surround
index b7be30b..8b9ba20 100644
--- a/Functions/Zle/surround
+++ b/Functions/Zle/surround
@@ -69,7 +69,11 @@ case $WIDGET in
       before="${(k)matching[(r)[$before:q]]}"
     fi
     CUTBUFFER="$before$CUTBUFFER$after"
-    zle .vi-put-after -n 1
+    if (( CURSOR )); then
+      zle .vi-put-after -n 1
+    else
+      zle .vi-put-before -n 1
+    fi
     CUTBUFFER="$save_cut" CURSOR="$save_cur"
   ;;
 esac