From 7a4a309973a2cfad2aefbfd6dfa8cc137005b227 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Fri, 5 Dec 2014 20:12:02 +0100 Subject: 33860: minor fixes to vi mode changes --- Src/Zle/zle_vi.c | 56 +++++++++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 31 deletions(-) (limited to 'Src/Zle/zle_vi.c') diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c index e9a367668..249e38f15 100644 --- a/Src/Zle/zle_vi.c +++ b/Src/Zle/zle_vi.c @@ -167,6 +167,8 @@ getvirange(int wf) Thingy k2; if (visual) { + if (!zlell) + return -1; pos = mark; vilinerange = (visual == 2); region_active = 0; @@ -179,17 +181,15 @@ getvirange(int wf) if (km) selectlocalmap(km); /* Now we need to execute the movement command, to see where it * - * actually goes. virangeflag here indicates to the movement * - * function that it should place the cursor at the end of the * - * range, rather than where the cursor would actually go if it * - * were executed normally. This makes a difference to some * - * commands, but not all. For example, if searching forward * - * for a character, under normal circumstances the cursor lands * - * on the character. For a range, the range must include the * - * character, so the cursor gets placed after the character if * - * virangeflag is set. vi-match-bracket needs to change the * - * value of virangeflag under some circumstances, meaning that * - * we need to change the *starting* position. */ + * actually goes. virangeflag here indicates to the movement * + * function that it should place the cursor at the end of the * + * range, rather than where the cursor would actually go if it * + * were executed normally. This makes a difference to some * + * commands, but not all. For example, if searching forward * + * for a character, under normal circumstances the cursor lands * + * on the character. For a range, the range must include the * + * character, so the cursor gets placed after the character if * + * virangeflag is set. */ zmod.flags &= ~MOD_TMULT; do { vilinerange = 0; @@ -202,10 +202,10 @@ getvirange(int wf) return -1; } /* - * With k2 == bindk, the command key is repeated: - * a number of lines is used. If the function used - * returns 1, we fail. - */ + * With k2 == bindk, the command key is repeated: + * a number of lines is used. If the function used + * returns 1, we fail. + */ if ((k2 == bindk) ? dovilinerange() : execzlefunc(k2, zlenoargs, 1)) ret = -1; if(vichgrepeat) @@ -217,8 +217,8 @@ getvirange(int wf) selectlocalmap(NULL); /* It is an error to use a non-movement command to delimit the * - * range. We here reject the case where the command modified * - * the line, or selected a different history line. */ + * range. We here reject the case where the command modified * + * the line, or selected a different history line. */ if (histline != hist1 || zlell != lastll || memcmp(zleline, lastline, zlell)) { histline = hist1; ZS_memcpy(zleline, lastline, zlell = lastll); @@ -228,21 +228,16 @@ getvirange(int wf) } /* Can't handle an empty file. Also, if the movement command * - * failed, or didn't move, it is an error. */ - if (!zlell || (zlecs == pos && mark == -1 && virangeflag != 2) || ret == -1) { + * failed, or didn't move, it is an error. */ + if (!zlell || (zlecs == pos && (mark == -1 || mark == zlecs) && + virangeflag != 2) || ret == -1) { mark = mpos; return -1; } - - /* vi-match-bracket changes the value of virangeflag when * - * moving to the opening bracket, meaning that we need to * - * change the *starting* position. */ - if (virangeflag == -1) - INCPOS(pos); virangeflag = 0; /* if the mark has moved, ignore the original cursor position * - * and use the mark. */ + * and use the mark. */ if (mark != -1) pos = mark; } @@ -883,7 +878,7 @@ vijoin(UNUSED(char **args)) } else if ((x = findeol()) == zlell || (visual && x >= mark)) return 1; - while (n) { + do { zlecs = x + 1; pos = zlecs; for (; zlecs != zlell && ZC_iblank(zleline[zlecs]); INCPOS(zlecs)) @@ -895,14 +890,13 @@ vijoin(UNUSED(char **args)) DECPOS(pos); if (ZC_iblank(zleline[pos])) { zlecs = pos; - return 0; + continue; } } spaceinline(1); zleline[zlecs] = ZWC(' '); - if ((!visual && --n < 2) || (x = findeol()) == zlell || (visual && x >= mark)) - return 0; - } + } while (!((!visual && --n < 2) || (x = findeol()) == zlell || (visual && x >= mark))); + return 0; } -- cgit 1.4.1