mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 9.1.1109: cmdexpand.c hard to read
Problem: cmdexpand.c hard to read Solution: refactor the file slightly (glepnir) closes: #16621 Signed-off-by: glepnir <glephunter@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
d7deeffe11
commit
977561a719
109
src/cmdexpand.c
109
src/cmdexpand.c
@@ -373,10 +373,7 @@ cmdline_pum_create(
|
|||||||
columns += vim_strsize(showmatches_gettail(matches[0]));
|
columns += vim_strsize(showmatches_gettail(matches[0]));
|
||||||
columns -= vim_strsize(matches[0]);
|
columns -= vim_strsize(matches[0]);
|
||||||
}
|
}
|
||||||
if (columns >= compl_startcol)
|
compl_startcol = MAX(0, compl_startcol - columns);
|
||||||
compl_startcol = 0;
|
|
||||||
else
|
|
||||||
compl_startcol -= columns;
|
|
||||||
|
|
||||||
// no default selection
|
// no default selection
|
||||||
compl_selected = -1;
|
compl_selected = -1;
|
||||||
@@ -735,94 +732,84 @@ win_redr_status_matches(
|
|||||||
* in "xp->xp_selected"
|
* in "xp->xp_selected"
|
||||||
*/
|
*/
|
||||||
static char_u *
|
static char_u *
|
||||||
get_next_or_prev_match(
|
get_next_or_prev_match(int mode, expand_T *xp)
|
||||||
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
|
||||||
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
|
||||||
if (findex == -1)
|
if (findex == -1)
|
||||||
findex = xp->xp_numfiles;
|
findex = xp->xp_numfiles;
|
||||||
--findex;
|
--findex;
|
||||||
}
|
}
|
||||||
else if (mode == WILD_NEXT)
|
else if (mode == WILD_NEXT)
|
||||||
++findex;
|
|
||||||
else if (mode == WILD_PAGEUP)
|
|
||||||
{
|
{
|
||||||
if (findex == 0)
|
// Select next file
|
||||||
// at the first entry, don't select any entries
|
findex = findex + 1;
|
||||||
findex = -1;
|
|
||||||
else if (findex == -1)
|
|
||||||
// no entry is selected. select the last entry
|
|
||||||
findex = xp->xp_numfiles - 1;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// go up by the pum height
|
|
||||||
ht = pum_get_height();
|
|
||||||
if (ht > 3)
|
|
||||||
ht -= 2;
|
|
||||||
findex -= ht;
|
|
||||||
if (findex < 0)
|
|
||||||
// few entries left, select the first entry
|
|
||||||
findex = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else // mode == WILD_PAGEDOWN
|
else // WILD_PAGEDOWN or WILD_PAGEUP
|
||||||
{
|
{
|
||||||
if (findex == xp->xp_numfiles - 1)
|
// Get the height of popup menu (used for both PAGEUP and PAGEDOWN)
|
||||||
// at the last entry, don't select any entries
|
ht = pum_get_height();
|
||||||
findex = -1;
|
if (ht > 3)
|
||||||
else if (findex == -1)
|
ht -= 2;
|
||||||
// no entry is selected. select the first entry
|
|
||||||
findex = 0;
|
if (mode == WILD_PAGEUP)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// go down by the pum height
|
if (findex == 0)
|
||||||
ht = pum_get_height();
|
// at the first entry, don't select any entries
|
||||||
if (ht > 3)
|
findex = -1;
|
||||||
ht -= 2;
|
else if (findex == -1)
|
||||||
findex += ht;
|
// no entry is selected. select the last entry
|
||||||
if (findex >= xp->xp_numfiles)
|
|
||||||
// few entries left, select the last entry
|
|
||||||
findex = xp->xp_numfiles - 1;
|
findex = xp->xp_numfiles - 1;
|
||||||
|
else
|
||||||
|
// go up by the pum height
|
||||||
|
findex = MAX(findex - ht, 0);
|
||||||
|
}
|
||||||
|
else // mode == WILD_PAGEDOWN
|
||||||
|
{
|
||||||
|
if (findex < 0)
|
||||||
|
// 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
|
||||||
|
findex = -1;
|
||||||
|
else
|
||||||
|
// go down by the pum height
|
||||||
|
findex = MIN(findex + ht, xp->xp_numfiles - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When wrapping around, return the original string, set findex to -1.
|
// Handle wrapping around
|
||||||
if (findex < 0)
|
if (findex < 0 || findex >= xp->xp_numfiles)
|
||||||
{
|
{
|
||||||
if (xp->xp_orig == NULL)
|
// If original string exists, return to it when wrapping around
|
||||||
findex = xp->xp_numfiles - 1;
|
if (xp->xp_orig != NULL)
|
||||||
else
|
|
||||||
findex = -1;
|
findex = -1;
|
||||||
}
|
|
||||||
if (findex >= xp->xp_numfiles)
|
|
||||||
{
|
|
||||||
if (xp->xp_orig == NULL)
|
|
||||||
findex = 0;
|
|
||||||
else
|
else
|
||||||
findex = -1;
|
// Wrap around to opposite end
|
||||||
|
findex = (findex < 0) ? xp->xp_numfiles - 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Display matches on screen
|
||||||
if (compl_match_array)
|
if (compl_match_array)
|
||||||
{
|
{
|
||||||
compl_selected = findex;
|
compl_selected = findex;
|
||||||
cmdline_pum_display();
|
cmdline_pum_display();
|
||||||
}
|
}
|
||||||
else if (p_wmnu)
|
else if (p_wmnu)
|
||||||
win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files,
|
win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, findex,
|
||||||
findex, cmd_showtail);
|
cmd_showtail);
|
||||||
|
|
||||||
xp->xp_selected = findex;
|
xp->xp_selected = findex;
|
||||||
|
// Return the original string or the selected match
|
||||||
if (findex == -1)
|
return vim_strsave(findex == -1 ? xp->xp_orig : xp->xp_files[findex]);
|
||||||
return vim_strsave(xp->xp_orig);
|
|
||||||
|
|
||||||
return vim_strsave(xp->xp_files[findex]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -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 */
|
||||||
|
/**/
|
||||||
|
1109,
|
||||||
/**/
|
/**/
|
||||||
1108,
|
1108,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user