summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/Zle/zle_hist.c9
-rw-r--r--Src/Zle/zle_misc.c18
-rw-r--r--Src/Zle/zle_move.c33
-rw-r--r--Src/Zle/zle_vi.c47
4 files changed, 78 insertions, 29 deletions
diff --git a/Src/Zle/zle_hist.c b/Src/Zle/zle_hist.c
index c69f8539a..0a4ead788 100644
--- a/Src/Zle/zle_hist.c
+++ b/Src/Zle/zle_hist.c
@@ -247,6 +247,11 @@ upline(void)
 	    if (zlecs > findbol() && invicmdmode())
 		DECCS();
 	}
+#ifdef MULTIBYTE_SUPPORT
+	else
+	    CCRIGHT();
+#endif
+	    
     }
     return n;
 }
@@ -331,6 +336,10 @@ downline(void)
 	    if (zlecs > findbol() && invicmdmode())
 		DECCS();
 	}
+#ifdef MULTIBYTE_SUPPORT
+	else
+	    CCRIGHT();
+#endif
     }
     return n;
 }
diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c
index 8379b2333..a6f7e803b 100644
--- a/Src/Zle/zle_misc.c
+++ b/Src/Zle/zle_misc.c
@@ -801,10 +801,20 @@ copyprevword(UNUSED(char **args))
 	for (;;) {
 	    t1 = t0;
 
-	    while (t0 && !ZC_iword(zleline[t0-1]))
-		t0--;
-	    while (t0 && ZC_iword(zleline[t0-1]))
-		t0--;
+	    while (t0) {
+		int prev = t0;
+		DECPOS(prev);
+		if (ZC_iword(zleline[prev]))
+		    break;
+		t0 = prev;
+	    }
+	    while (t0) {
+		int prev = t0;
+		DECPOS(prev);
+		if (!ZC_iword(zleline[prev]))
+		    break;
+		t0 = prev;
+	    }
 
 	    if (!--count)
 		break;
diff --git a/Src/Zle/zle_move.c b/Src/Zle/zle_move.c
index 9b35660f1..5b02616a2 100644
--- a/Src/Zle/zle_move.c
+++ b/Src/Zle/zle_move.c
@@ -307,11 +307,19 @@ beginningofline(char **args)
 	return ret;
     }
     while (n--) {
+	int pos;
+
 	if (zlecs == 0)
 	    return 0;
-	if (zleline[zlecs - 1] == '\n')
-	    if (!--zlecs)
+	pos = zlecs;
+	DECPOS(pos);
+	if (zleline[pos] == '\n') {
+	    zlecs = pos;
+	    if (!zlecs)
 		return 0;
+	}
+
+	/* works OK with combining chars since '\n' must be on its own */
 	while (zlecs && zleline[zlecs - 1] != '\n')
 	    zlecs--;
     }
@@ -359,11 +367,19 @@ beginningoflinehist(char **args)
 	return ret;
     }
     while (n) {
+	int pos;
+
 	if (zlecs == 0)
 	    break;
-	if (zleline[zlecs - 1] == '\n')
-	    if (!--zlecs)
+	pos = zlecs;
+	DECPOS(pos);
+	if (zleline[pos] == '\n') {
+	    zlecs = pos;
+	    if (!pos)
 		break;
+	}
+
+	/* works OK with combining chars since '\n' must be on its own */
 	while (zlecs && zleline[zlecs - 1] != '\n')
 	    zlecs--;
 	n--;
@@ -554,12 +570,15 @@ vimatchbracket(UNUSED(char **args))
 	oth = '[';
 	break;
     default:
-	zlecs++;
+	INCCS();
 	goto otog;
     }
     ct = 1;
     while (zlecs >= 0 && zlecs < zlell && ct) {
-	zlecs += dir;
+	if (dir < 0)
+	    DECCS();
+	else
+	    INCCS();
 	if (zleline[zlecs] == oth)
 	    ct--;
 	else if (zleline[zlecs] == me)
@@ -634,7 +653,7 @@ viendofline(UNUSED(char **args))
 	}
 	zlecs = findeol() + 1;
     }
-    zlecs--;
+    DECCS();
     lastcol = 1<<30;
     return 0;
 }
diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c
index d966a29ce..173a49ef9 100644
--- a/Src/Zle/zle_vi.c
+++ b/Src/Zle/zle_vi.c
@@ -262,7 +262,7 @@ dovilinerange(void)
 	    zlecs = pos;
 	    return 1;
 	}
-	zlecs--;
+	DECCS();
     } else {
 	while(n++ && zlecs >= 0)
 	    zlecs = findbol() - 1;
@@ -270,7 +270,7 @@ dovilinerange(void)
 	    zlecs = pos;
 	    return 1;
 	}
-	zlecs++;
+	INCCS();
     }
     virangeflag = 2;
     return 0;
@@ -281,7 +281,7 @@ int
 viaddnext(UNUSED(char **args))
 {
     if (zlecs != findeol())
-	zlecs++;
+	INCCS();
     startvitext(1);
     return 0;
 }
@@ -776,7 +776,7 @@ viputbefore(UNUSED(char **args))
 	    zlecs += buf->len;
 	}
 	if (zlecs)
-	    zlecs--;
+	    DECCS();
     }
     return 0;
 }
@@ -819,20 +819,27 @@ viputafter(UNUSED(char **args))
 int
 vijoin(UNUSED(char **args))
 {
-    int x;
+    int x, pos;
 
     startvichange(-1);
     if ((x = findeol()) == zlell)
 	return 1;
     zlecs = x + 1;
-    for (x = 1; zlecs != zlell && ZC_iblank(zleline[zlecs]); zlecs++, x++);
+    pos = zlecs;
+    for (; zlecs != zlell && ZC_iblank(zleline[zlecs]); INCPOS(zlecs))
+	;
+    x = 1 + (zlecs - pos);
     backdel(x, CUT_RAW);
-    if (zlecs && ZC_iblank(zleline[zlecs-1]))
-	zlecs--;
-    else {
-	spaceinline(1);
-	zleline[zlecs] = ZWC(' ');
+    if (zlecs) {
+	int pos = zlecs;
+	DECPOS(pos);
+	if (ZC_iblank(zleline[pos])) {
+	    zlecs = pos;
+	    return 0;
+	}
     }
+    spaceinline(1);
+    zleline[zlecs] = ZWC(' ');
     return 0;
 }
 
@@ -851,10 +858,10 @@ viswapcase(UNUSED(char **args))
 	    zleline[zlecs] = ZC_toupper(zleline[zlecs]);
 	else if (ZC_iupper(zleline[zlecs]))
 	    zleline[zlecs] = ZC_tolower(zleline[zlecs]);
-	zlecs++;
+	INCCS();
     }
     if (zlecs && zlecs == eol)
-	zlecs--;
+	DECCS();
     return 0;
 }
 
@@ -909,7 +916,7 @@ vikilleol(UNUSED(char **args))
 	return 1;
     }
     /* delete to end of line */
-    forekill(findeol() - zlecs, 0);
+    forekill(findeol() - zlecs, CUT_RAW);
     return 0;
 }
 
@@ -925,13 +932,17 @@ vipoundinsert(UNUSED(char **args))
 	spaceinline(1);
 	zleline[zlecs] = '#';
 	if(zlecs <= viinsbegin)
-	    viinsbegin++;
-	zlecs = oldcs + (zlecs <= oldcs);
+	    INCPOS(viinsbegin);
+	if (zlecs <= oldcs)
+	    INCPOS(oldcs);
+	zlecs = oldcs;
     } else {
 	foredel(1, 0);
 	if (zlecs < viinsbegin)
-	    viinsbegin--;
-	zlecs = oldcs - (zlecs < oldcs);
+	    DECPOS(viinsbegin);
+	if (zlecs < oldcs)
+	    DECPOS(oldcs);
+	zlecs = oldcs;
     }
     return 0;
 }