mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-21 04:11:13 +02:00
unposted: fix position of cursor on forward pattern searching
This commit is contained in:
parent
1fc8484f05
commit
3587f599b0
2 changed files with 40 additions and 11 deletions
|
@ -975,7 +975,8 @@ get_isrch_spot(int num, int *hlp, int *posp, int *pat_hlp, int *pat_posp,
|
||||||
* never matches when searching forwards.
|
* never matches when searching forwards.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
isearch_newpos(LinkList matchlist, int curpos, int dir)
|
isearch_newpos(LinkList matchlist, int curpos, int dir,
|
||||||
|
int *endmatchpos)
|
||||||
{
|
{
|
||||||
LinkNode node;
|
LinkNode node;
|
||||||
|
|
||||||
|
@ -983,17 +984,21 @@ isearch_newpos(LinkList matchlist, int curpos, int dir)
|
||||||
for (node = lastnode(matchlist);
|
for (node = lastnode(matchlist);
|
||||||
node != (LinkNode)matchlist; decnode(node)) {
|
node != (LinkNode)matchlist; decnode(node)) {
|
||||||
Repldata rdata = (Repldata)getdata(node);
|
Repldata rdata = (Repldata)getdata(node);
|
||||||
if (rdata->b <= curpos)
|
if (rdata->b <= curpos) {
|
||||||
|
*endmatchpos = rdata->e;
|
||||||
return rdata->b;
|
return rdata->b;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for (node = firstnode(matchlist);
|
for (node = firstnode(matchlist);
|
||||||
node; incnode(node)) {
|
node; incnode(node)) {
|
||||||
Repldata rdata = (Repldata)getdata(node);
|
Repldata rdata = (Repldata)getdata(node);
|
||||||
if (rdata->b >= curpos)
|
if (rdata->b >= curpos) {
|
||||||
|
*endmatchpos = rdata->e;
|
||||||
return rdata->b;
|
return rdata->b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1037,9 +1042,10 @@ doisearch(char **args, int dir, int pattern)
|
||||||
*/
|
*/
|
||||||
int odir = dir, sens = zmult == 1 ? 3 : 1;
|
int odir = dir, sens = zmult == 1 ? 3 : 1;
|
||||||
/*
|
/*
|
||||||
* The number of the history line we are looking at and the
|
* hl: the number of the history line we are looking at
|
||||||
* character position into it, essentially the cursor position
|
* pos: the character position into it. On backward matches the
|
||||||
* except we don't update that as frequently.
|
* cursor will be set to this; on forward matches to the end
|
||||||
|
* of the matched string
|
||||||
*/
|
*/
|
||||||
int hl = histline, pos;
|
int hl = histline, pos;
|
||||||
/*
|
/*
|
||||||
|
@ -1139,7 +1145,13 @@ doisearch(char **args, int dir, int pattern)
|
||||||
nomatch = 0;
|
nomatch = 0;
|
||||||
statusline = ibuf + NORM_PROMPT_POS;
|
statusline = ibuf + NORM_PROMPT_POS;
|
||||||
} else if (sbptr > 0) {
|
} else if (sbptr > 0) {
|
||||||
|
/* The matched text, used as flag that we matched */
|
||||||
char *t = NULL;
|
char *t = NULL;
|
||||||
|
/*
|
||||||
|
* When forward matching, position for the cursor.
|
||||||
|
* When backward matching, the position is pos.
|
||||||
|
*/
|
||||||
|
int forwardmatchpos = 0;
|
||||||
last_line = zt;
|
last_line = zt;
|
||||||
|
|
||||||
sbuf[sbptr] = '\0';
|
sbuf[sbptr] = '\0';
|
||||||
|
@ -1219,7 +1231,9 @@ doisearch(char **args, int dir, int pattern)
|
||||||
* skip_pos applies to the whole line in
|
* skip_pos applies to the whole line in
|
||||||
* this mode.
|
* this mode.
|
||||||
*/
|
*/
|
||||||
if (!skip_pos && pattry(patprog, zt))
|
if (!skip_pos &&
|
||||||
|
pattryrefs(patprog, zt, -1, -1, 0, NULL, NULL,
|
||||||
|
&forwardmatchpos))
|
||||||
t = zt;
|
t = zt;
|
||||||
} else {
|
} else {
|
||||||
if (!matchlist && !skip_pos) {
|
if (!matchlist && !skip_pos) {
|
||||||
|
@ -1254,16 +1268,17 @@ doisearch(char **args, int dir, int pattern)
|
||||||
newpos = pos + 1;
|
newpos = pos + 1;
|
||||||
}
|
}
|
||||||
newpos = isearch_newpos(matchlist, newpos,
|
newpos = isearch_newpos(matchlist, newpos,
|
||||||
dir);
|
dir, &forwardmatchpos);
|
||||||
/* need a new list next time if off the end */
|
/* need a new list next time if off the end */
|
||||||
if (newpos < 0) {
|
if (newpos < 0) {
|
||||||
freematchlist(matchlist);
|
freematchlist(matchlist);
|
||||||
matchlist = NULL;
|
matchlist = NULL;
|
||||||
} else
|
} else {
|
||||||
t = zt + newpos;
|
t = zt + newpos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
skip_pos = 0;
|
skip_pos = 0;
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
|
@ -1300,6 +1315,8 @@ doisearch(char **args, int dir, int pattern)
|
||||||
t = zt;
|
t = zt;
|
||||||
} else
|
} else
|
||||||
t = zlinefind(zt, pos, sbuf, dir, sens);
|
t = zlinefind(zt, pos, sbuf, dir, sens);
|
||||||
|
if (t)
|
||||||
|
forwardmatchpos = pos + sbptr - (sbuf[0] == '^');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (t) {
|
if (t) {
|
||||||
|
@ -1348,8 +1365,10 @@ doisearch(char **args, int dir, int pattern)
|
||||||
*/
|
*/
|
||||||
if (t || (nosearch && !nomatch)) {
|
if (t || (nosearch && !nomatch)) {
|
||||||
zle_setline(he);
|
zle_setline(he);
|
||||||
zlemetacs = pos +
|
if (dir == 1)
|
||||||
(dir == 1 ? sbptr - (sbuf[0] == '^') : 0);
|
zlemetacs = forwardmatchpos;
|
||||||
|
else
|
||||||
|
zlemetacs = pos;
|
||||||
statusline = ibuf + NORM_PROMPT_POS;
|
statusline = ibuf + NORM_PROMPT_POS;
|
||||||
nomatch = 0;
|
nomatch = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1861,6 +1861,9 @@ pattrylen(Patprog prog, char *string, int len, int unmetalen, int offset)
|
||||||
* backreferences. On entry, *nump should contain the maximum number
|
* backreferences. On entry, *nump should contain the maximum number
|
||||||
* of positions to report. In this case the match, mbegin, mend
|
* of positions to report. In this case the match, mbegin, mend
|
||||||
* arrays are not altered.
|
* arrays are not altered.
|
||||||
|
*
|
||||||
|
* If nump is NULL but endp is not NULL, then *endp is set to the
|
||||||
|
* end position of the match, taking into account patinstart.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
|
@ -2222,6 +2225,13 @@ pattryrefs(Patprog prog, char *string, int stringlen, int unmetalen,
|
||||||
setaparam("mend", mendarr);
|
setaparam("mend", mendarr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!nump && endp) {
|
||||||
|
/*
|
||||||
|
* We just need the overall end position.
|
||||||
|
*/
|
||||||
|
*endp = CHARSUB(patinstart, patinput) + patoffset;
|
||||||
|
}
|
||||||
|
|
||||||
ret = 1;
|
ret = 1;
|
||||||
} else
|
} else
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
Loading…
Reference in a new issue