Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: vi-backward-kill-word
- X-seq: zsh-workers 24860
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: vi-backward-kill-word
- Date: Mon, 21 Apr 2008 18:57:02 +0100
- In-reply-to: <20080421182728.3450104d@news01>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- Organization: CSR
- References: <A2142905-01C6-4D18-9CE2-EC23B8DE2F03@xxxxxxxxxxxxxxxxx> <20080421182728.3450104d@news01>
On Mon, 21 Apr 2008 18:27:28 +0100
Peter Stephenson <pws@xxxxxxx> wrote:
> I think there's still a problem
> in overstrike mode when you enter a combining character; it'll advance too
> far right. I'll look at that separately.
I think this deals with it.
I saw some oddities with undo, but that may simply be because in a version
I hadn't quite got right the cursor position was screwy. I didn't see them
with the final version.
Index: Src/Zle/zle_misc.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_misc.c,v
retrieving revision 1.50
diff -u -r1.50 zle_misc.c
--- Src/Zle/zle_misc.c 21 Apr 2008 17:30:35 -0000 1.50
+++ Src/Zle/zle_misc.c 21 Apr 2008 17:53:42 -0000
@@ -50,19 +50,43 @@
if (insmode)
spaceinline(m * len);
else {
- int pos = zlecs, count = m * len, i = count, diff;
+ int pos = zlecs, diff, i;
+
+ /*
+ * Calculate the number of character positions we are
+ * going to be using. The algorithm is that
+ * anything that shows up as a logical single character
+ * (i.e. even if control, or double width, or with combining
+ * characters) is treated as 1 for the purpose of replacing
+ * what's there already.
+ */
+ for (i = 0, count = 0; i < len; i++) {
+ int width = wcwidth(zstr[i]);
+ count += (width != 0) ? 1 : 0;
+ }
/*
* Ensure we replace a complete combining character
* for each character we overwrite.
*/
- while (pos < zlell && i--) {
+ for (i = count; pos < zlell && i--; ) {
INCPOS(pos);
}
- diff = pos - zlecs - count;
+ /*
+ * Calculate how many raw line places we need.
+ * pos - zlecs is the raw line distance we're replacing,
+ * m * len the number we're inserting.
+ */
+ diff = pos - zlecs - m * len;
if (diff < 0) {
spaceinline(-diff);
- } else if (diff > 0)
- foredel(diff, CUT_RAW);
+ } else if (diff > 0) {
+ /*
+ * We use shiftchars() here because we don't
+ * want combining char alignment fixed up: we
+ * are going to write over any that remain.
+ */
+ shiftchars(zlecs, diff);
+ }
}
while (m--)
for (s = zstr, count = len; count; s++, count--)
Index: Src/Zle/zle_utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_utils.c,v
retrieving revision 1.51
diff -u -r1.51 zle_utils.c
--- Src/Zle/zle_utils.c 21 Apr 2008 10:13:31 -0000 1.51
+++ Src/Zle/zle_utils.c 21 Apr 2008 17:53:42 -0000
@@ -450,7 +450,7 @@
}
/**/
-static void
+void
shiftchars(int to, int cnt)
{
if (mark >= to + cnt)
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
Messages sorted by:
Reverse Date,
Date,
Thread,
Author