0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 9.1.1112: Inconsistencies in get_next_or_prev_match()

Problem:  Inconsistencies in get_next_or_prev_match() (after 9.1.1109).
Solution: Change "file" to "entry" or "match" in comments.  Use the same
          order of branches for PAGEUP and PAGEDOWN (zeertzjq).

closes: #16633

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq
2025-02-14 17:59:31 +01:00
committed by Christian Brabandt
parent faf4112cdc
commit b6c900be9c
2 changed files with 14 additions and 11 deletions

View File

@@ -737,21 +737,22 @@ get_next_or_prev_match(int mode, expand_T *xp)
int findex = xp->xp_selected; int findex = xp->xp_selected;
int ht; int ht;
// When no files found, return NULL // When no matches found, return NULL
if (xp->xp_numfiles <= 0) if (xp->xp_numfiles <= 0)
return NULL; return NULL;
if (mode == WILD_PREV) if (mode == WILD_PREV)
{ {
// Select last file if at start // Select the last entry if at original text
if (findex == -1) if (findex == -1)
findex = xp->xp_numfiles; findex = xp->xp_numfiles;
// Otherwise select the previous entry
--findex; --findex;
} }
else if (mode == WILD_NEXT) else if (mode == WILD_NEXT)
{ {
// Select next file // Select the next entry
findex = findex + 1; ++findex;
} }
else // WILD_PAGEDOWN or WILD_PAGEUP else // WILD_PAGEDOWN or WILD_PAGEUP
{ {
@@ -765,7 +766,7 @@ get_next_or_prev_match(int mode, expand_T *xp)
if (findex == 0) if (findex == 0)
// at the first entry, don't select any entries // at the first entry, don't select any entries
findex = -1; findex = -1;
else if (findex == -1) else if (findex < 0)
// no entry is selected. select the last entry // no entry is selected. select the last entry
findex = xp->xp_numfiles - 1; findex = xp->xp_numfiles - 1;
else else
@@ -774,12 +775,12 @@ get_next_or_prev_match(int mode, expand_T *xp)
} }
else // mode == WILD_PAGEDOWN else // mode == WILD_PAGEDOWN
{ {
if (findex < 0) if (findex >= xp->xp_numfiles - 1)
// no entry is selected, select the first entry
findex = 0;
else if (findex >= xp->xp_numfiles - 1)
// at the last entry, don't select any entries // at the last entry, don't select any entries
findex = -1; findex = -1;
else if (findex < 0)
// no entry is selected, select the first entry
findex = 0;
else else
// go down by the pum height // go down by the pum height
findex = MIN(findex + ht, xp->xp_numfiles - 1); findex = MIN(findex + ht, xp->xp_numfiles - 1);
@@ -789,7 +790,7 @@ get_next_or_prev_match(int mode, expand_T *xp)
// Handle wrapping around // Handle wrapping around
if (findex < 0 || findex >= xp->xp_numfiles) if (findex < 0 || findex >= xp->xp_numfiles)
{ {
// If original string exists, return to it when wrapping around // If original text exists, return to it when wrapping around
if (xp->xp_orig != NULL) if (xp->xp_orig != NULL)
findex = -1; findex = -1;
else else
@@ -808,7 +809,7 @@ get_next_or_prev_match(int mode, expand_T *xp)
cmd_showtail); cmd_showtail);
xp->xp_selected = findex; xp->xp_selected = findex;
// Return the original string or the selected match // Return the original text or the selected match
return vim_strsave(findex == -1 ? xp->xp_orig : xp->xp_files[findex]); return vim_strsave(findex == -1 ? xp->xp_orig : xp->xp_files[findex]);
} }

View File

@@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1112,
/**/ /**/
1111, 1111,
/**/ /**/