Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: replace chars in a selection
- X-seq: zsh-workers 33738
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: PATCH: replace chars in a selection
- Date: Fri, 21 Nov 2014 10:31:59 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1416562323; bh=GIpoiK77dzTpofU44ugW3PLNSiNJJR/uBBpQUD4ObzA=; h=From:To:Subject:Date:From:Subject; b=P+FkKC7ulo7KgqwZurMmGKSEtVb6p6xCVmNeKeG07knT13mK3/Le66b3dFwVvBeWCWxY+kUDvl4208Nxh7ZqE4p5cB4b7J01h+gzvv67siT3/ZfGDpFjkdeIdNryQquDl6lqNjbvdZVr64ddBtF7JbKw4A8IWH8YiA3SnGH/aTMigDK/sVO7+C+tXqow/JoLPn+wYppThkfSxlpMu94NtDtoCeYrVDgyfciYLCE11P4TQl/5M9xfjh18hiUTzSUJinOgsCve5Ic+QXGAtIWsnCxy1hsZp8LXPL1y7ksnRhI+zJ/jbA7xwc0cYMHLZfw4boyCJQhajurjqstwc2uljQ==
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s2048; d=yahoo.co.uk; b=ulGw+XM8RjY58MVg0IHhCo3PU0pGyKBq7GVsqvy9FM+q8El9yFJBKotgOvZW4GxIeOqHCFrlGsaVJe3JXSuDy7ItAKcdGjGXeHaDlbTZSdlBY4Fpb7GVBweG/iZLXp125ALX/coU16H7Alqm9m4SVr40v+hjBJWPhFyxU9APtalg71+dQ1RU9MykXxIaOlA1Z2nMi/T1wYF7c1ubVsb9vQvCVO9jBRn9MUIBvSWHZ5aaPWKPYu2XU6yqvnu6CoAzfcC1wAP19tbvj7GL+QOoKb9z9hlvBse+RcezHyqttDS4MMJLa3IDMla5JxChFa6uwHHDSM/Z4kyNbpkO2d93Cg==;
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
vi-replace-chars needs to take account of a selection.
Oliver
diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c
index b0d69f1..e9a3676 100644
--- a/Src/Zle/zle_vi.c
+++ b/Src/Zle/zle_vi.c
@@ -257,6 +257,7 @@ getvirange(int wf)
pos = tmp;
}
+ /* visual selection mode needs to include additional position */
if (visual == 1 && invicmdmode())
INCPOS(pos);
@@ -576,16 +577,40 @@ vireplacechars(UNUSED(char **args))
int n = zmult, fail = 0, newchars = 0;
if (n > 0) {
- int pos = zlecs;
- while (n-- > 0) {
- if (pos == zlell || zleline[pos] == ZWC('\n')) {
- fail = 1;
- break;
+ if (region_active) {
+ int a, b;
+ if (region_active == 1) {
+ if (mark > zlecs) {
+ a = zlecs;
+ b = mark;
+ } else {
+ a = mark;
+ b = zlecs;
+ }
+ INCPOS(b);
+ } else
+ regionlines(&a, &b);
+ zlecs = a;
+ if (b > zlell)
+ b = zlell;
+ n = b - a;
+ while (a < b) {
+ newchars++;
+ INCPOS(a);
+ }
+ region_active = 0;
+ } else {
+ int pos = zlecs;
+ while (n-- > 0) {
+ if (pos == zlell || zleline[pos] == ZWC('\n')) {
+ fail = 1;
+ break;
+ }
+ newchars++;
+ INCPOS(pos);
}
- newchars++;
- INCPOS(pos);
+ n = pos - zlecs;
}
- n = pos - zlecs;
}
startvichange(1);
/* check argument range */
@@ -617,6 +642,8 @@ vireplacechars(UNUSED(char **args))
* buffer offset.
* Use shiftchars so as not to adjust the cursor position;
* we are overwriting anything that remains directly.
+ * With a selection this will replace newlines which vim
+ * doesn't do but this simplifies things a lot.
*/
if (n > newchars)
shiftchars(zlecs, n - newchars);
diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst
index 6b7ca56..1185a08 100644
--- a/Test/X02zlevi.ztst
+++ b/Test/X02zlevi.ztst
@@ -289,6 +289,11 @@
>BUFFER: x g
>CURSOR: 2
+ zletest $'line end\eOstart 1 back new\e0verawvrbwevbrcwvj0erdwv$re'
+0:replace characters in selections
+>BUFFER: aaaaa b cccc dddddddd eee
+>CURSOR: 24
+
zletest $'one two\eyb0vep'
0:put over selection at start of buffer
>BUFFER: tw two
Messages sorted by:
Reverse Date,
Date,
Thread,
Author