about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2008-04-21 17:58:58 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2008-04-21 17:58:58 +0000
commita58d02fd2e11f8453b912859b2f774b6cadace4c (patch)
tree10d411adb6c6f0d544cc8b1e7af9b96f5403ab5e /Src
parentf9224e5a0493a5f41882988cf467c80a531e331f (diff)
downloadzsh-a58d02fd2e11f8453b912859b2f774b6cadace4c.tar.gz
zsh-a58d02fd2e11f8453b912859b2f774b6cadace4c.tar.xz
zsh-a58d02fd2e11f8453b912859b2f774b6cadace4c.zip
24860: better overwrite mode
Diffstat (limited to 'Src')
-rw-r--r--Src/Zle/zle_misc.c34
-rw-r--r--Src/Zle/zle_utils.c2
2 files changed, 30 insertions, 6 deletions
diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c
index e00f22b04..d3a9413f3 100644
--- a/Src/Zle/zle_misc.c
+++ b/Src/Zle/zle_misc.c
@@ -50,19 +50,43 @@ doinsert(ZLE_STRING_T zstr, int len)
     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--)
diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index 8b298f59d..acc6c3717 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -450,7 +450,7 @@ spaceinline(int ct)
 }
 
 /**/
-static void
+void
 shiftchars(int to, int cnt)
 {
     if (mark >= to + cnt)