about summary refs log tree commit diff
path: root/Src/Zle/zle_hist.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2008-04-26 21:26:28 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2008-04-26 21:26:28 +0000
commit3587f599b0b8da18e090aa2b843f0229df4cb83b (patch)
treefc4a0cb6b4ef0f48535d4a5e5bcc652366fc2d37 /Src/Zle/zle_hist.c
parent1fc8484f05abd32b3d4009f2ab1f95e4d95c6b78 (diff)
downloadzsh-3587f599b0b8da18e090aa2b843f0229df4cb83b.tar.gz
zsh-3587f599b0b8da18e090aa2b843f0229df4cb83b.tar.xz
zsh-3587f599b0b8da18e090aa2b843f0229df4cb83b.zip
unposted: fix position of cursor on forward pattern searching
Diffstat (limited to 'Src/Zle/zle_hist.c')
-rw-r--r--Src/Zle/zle_hist.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/Src/Zle/zle_hist.c b/Src/Zle/zle_hist.c
index b43e76699..9f0288d0b 100644
--- a/Src/Zle/zle_hist.c
+++ b/Src/Zle/zle_hist.c
@@ -975,7 +975,8 @@ get_isrch_spot(int num, int *hlp, int *posp, int *pat_hlp, int *pat_posp,
  * never matches when searching forwards.
  */
 static int
-isearch_newpos(LinkList matchlist, int curpos, int dir)
+isearch_newpos(LinkList matchlist, int curpos, int dir,
+	       int *endmatchpos)
 {
     LinkNode node;
 
@@ -983,15 +984,19 @@ isearch_newpos(LinkList matchlist, int curpos, int dir)
 	for (node = lastnode(matchlist);
 	     node != (LinkNode)matchlist; decnode(node)) {
 	    Repldata rdata = (Repldata)getdata(node);
-	    if (rdata->b <= curpos)
+	    if (rdata->b <= curpos) {
+		*endmatchpos = rdata->e;
 		return rdata->b;
+	    }
 	}
     } else {
 	for (node = firstnode(matchlist);
 	     node; incnode(node)) {
 	    Repldata rdata = (Repldata)getdata(node);
-	    if (rdata->b >= curpos)
+	    if (rdata->b >= curpos) {
+		*endmatchpos = rdata->e;
 		return rdata->b;
+	    }
 	}
     }
 
@@ -1037,9 +1042,10 @@ doisearch(char **args, int dir, int pattern)
      */
     int odir = dir, sens = zmult == 1 ? 3 : 1;
     /*
-     * The number of the history line we are looking at and the
-     * character position into it, essentially the cursor position
-     * except we don't update that as frequently.
+     * hl: the number of the history line we are looking at
+     * pos: the character position into it.  On backward matches the
+     *      cursor will be set to this; on forward matches to the end
+     *      of the matched string
      */
     int hl = histline, pos;
     /*
@@ -1139,7 +1145,13 @@ doisearch(char **args, int dir, int pattern)
     	    nomatch = 0;
 	    statusline = ibuf + NORM_PROMPT_POS;
 	} else if (sbptr > 0) {
+	    /* The matched text, used as flag that we matched */
 	    char *t = NULL;
+	    /*
+	     * When forward matching, position for the cursor.
+	     * When backward matching, the position is pos.
+	     */
+	    int forwardmatchpos = 0;
 	    last_line = zt;
 
 	    sbuf[sbptr] = '\0';
@@ -1219,7 +1231,9 @@ doisearch(char **args, int dir, int pattern)
 			     * skip_pos applies to the whole line in
 			     * this mode.
 			     */
-			    if (!skip_pos && pattry(patprog, zt))
+			    if (!skip_pos &&
+				pattryrefs(patprog, zt, -1, -1, 0, NULL, NULL,
+					   &forwardmatchpos))
 				t = zt;
 			} else {
 			    if (!matchlist && !skip_pos) {
@@ -1254,13 +1268,14 @@ doisearch(char **args, int dir, int pattern)
 					newpos = pos + 1;
 				}
 				newpos = isearch_newpos(matchlist, newpos,
-							dir);
+							dir, &forwardmatchpos);
 				/* need a new list next time if off the end */
 				if (newpos < 0) {
 				    freematchlist(matchlist);
 				    matchlist = NULL;
-				} else
+				} else {
 				    t = zt + newpos;
+				}
 			    }
 			}
 		    }
@@ -1300,6 +1315,8 @@ doisearch(char **args, int dir, int pattern)
 				t = zt;
 			} else
 			    t = zlinefind(zt, pos, sbuf, dir, sens);
+			if (t)
+			    forwardmatchpos = pos + sbptr - (sbuf[0] == '^');
 		    }
 		}
 		if (t) {
@@ -1348,8 +1365,10 @@ doisearch(char **args, int dir, int pattern)
 	     */
 	    if (t || (nosearch && !nomatch)) {
 		zle_setline(he);
-		zlemetacs = pos +
-		    (dir == 1 ? sbptr - (sbuf[0] == '^') : 0);
+		if (dir == 1)
+		    zlemetacs = forwardmatchpos;
+		else
+		    zlemetacs = pos;
 		statusline = ibuf + NORM_PROMPT_POS;
 		nomatch = 0;
 	    }