about summary refs log tree commit diff
path: root/Src/Zle
diff options
context:
space:
mode:
authorOliver Kiddle <opk@zsh.org>2014-11-30 23:37:01 +0100
committerOliver Kiddle <opk@zsh.org>2014-11-30 23:37:01 +0100
commitd2505f108e4144cde656a3568571fd0c195cdd1f (patch)
tree89700c39691a3e3db3270c73de7c28b8b2263e00 /Src/Zle
parent62aa03931753e532cbae0fa56725bb5e2a757dff (diff)
downloadzsh-d2505f108e4144cde656a3568571fd0c195cdd1f.tar.gz
zsh-d2505f108e4144cde656a3568571fd0c195cdd1f.tar.xz
zsh-d2505f108e4144cde656a3568571fd0c195cdd1f.zip
33823: overwrite mode shouldn't replace newlines
Diffstat (limited to 'Src/Zle')
-rw-r--r--Src/Zle/zle_misc.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c
index a220a6bc8..a1dc3fa5c 100644
--- a/Src/Zle/zle_misc.c
+++ b/Src/Zle/zle_misc.c
@@ -47,13 +47,13 @@ doinsert(ZLE_STRING_T zstr, int len)
     iremovesuffix(c1, 0);
     invalidatelist();
 
-    if (insmode)
+    /* In overwrite mode, don't replace newlines. */
+    if (insmode || zleline[zlecs] == ZWC('\n'))
 	spaceinline(m * len);
     else
-#ifdef MULTIBYTE_SUPPORT
     {
 	int pos = zlecs, diff, i;
-
+#ifdef MULTIBYTE_SUPPORT
 	/*
 	 * Calculate the number of character positions we are
 	 * going to be using.  The algorithm is that
@@ -68,15 +68,18 @@ doinsert(ZLE_STRING_T zstr, int len)
 	 * useful there anyway and this doesn't cause any
 	 * particular harm.
 	 */
-	for (i = 0, count = 0; i < len; i++) {
+	for (i = 0, count = 0; i < len * m; i++) {
 	    if (!IS_COMBINING(zstr[i]))
 		count++;
 	}
+#else
+	count = len * m;
+#endif
 	/*
-	 * Ensure we replace a complete combining character
-	 * for each character we overwrite.
+	 * Ensure we replace a complete combining characterfor each
+	 * character we overwrite. Switch to inserting at first newline.
 	 */
-	for (i = count; pos < zlell && i--; ) {
+	for (i = count; pos < zlell && zleline[pos] != ZWC('\n') && i--; ) {
 	    INCPOS(pos);
 	}
 	/*
@@ -96,10 +99,6 @@ doinsert(ZLE_STRING_T zstr, int len)
 	    shiftchars(zlecs, diff);
 	}
     }
-#else
-    if (zlecs + m * len > zlell)
-	spaceinline(zlecs + m * len - zlell);
-#endif
     while (m--)
 	for (s = zstr, count = len; count; s++, count--)
 	    zleline[zlecs++] = *s;