summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Src/Zle/zle_misc.c34
-rw-r--r--Src/Zle/zle_utils.c2
3 files changed, 33 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 09f6cc096..3f8cbad7a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2008-04-21 Peter Stephenson <pws@csr.com>
+ * 24860: Src/Zle/zle_misc.c, Src/Zle/zle_utils.c: better
+ overwrite mode.
+
* 24859: Src/Zle/zle_misc.c, Src/Zle/zle_vi.c, Src/Zle/zle_word.c:
overwriting combining characters and replacing them and appending
after them in vi mode.
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)