summaryrefslogtreecommitdiffstats
path: root/src/cmdexpand.c
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2022-03-16 13:33:53 +0000
committerBram Moolenaar <Bram@vim.org>2022-03-16 13:33:53 +0000
commit5cffa8df7e3c28681b9e5deef6df395784359b6b (patch)
tree0164635aec712ab5ca866b9f7354288664f568b1 /src/cmdexpand.c
parentfe8e9f674036f3206b0080f4a931c991cf142f8b (diff)
patch 8.2.4579: cannot use page-up and page-down in the cmdline popup menuv8.2.4579
Problem: Cannot use page-up and page-down in the command line completion popup menu. Solution: Check for to page-up and page-down keys. (Yegappan Lakshmanan, closes #9960)
Diffstat (limited to 'src/cmdexpand.c')
-rw-r--r--src/cmdexpand.c56
1 files changed, 49 insertions, 7 deletions
diff --git a/src/cmdexpand.c b/src/cmdexpand.c
index c408bd099c..5ba6b084d3 100644
--- a/src/cmdexpand.c
+++ b/src/cmdexpand.c
@@ -224,7 +224,8 @@ nextwild(
i = (int)(xp->xp_pattern - ccline->cmdbuff);
xp->xp_pattern_len = ccline->cmdpos - i;
- if (type == WILD_NEXT || type == WILD_PREV)
+ if (type == WILD_NEXT || type == WILD_PREV
+ || type == WILD_PAGEUP || type == WILD_PAGEDOWN)
{
// Get next/previous match for a previous expanded pattern.
p2 = ExpandOne(xp, NULL, NULL, 0, type);
@@ -404,7 +405,7 @@ int cmdline_compl_startcol(void)
/*
* Get the next or prev cmdline completion match. The index of the match is set
- * in 'p_findex'
+ * in "p_findex"
*/
static char_u *
get_next_or_prev_match(
@@ -414,6 +415,7 @@ get_next_or_prev_match(
char_u *orig_save)
{
int findex = *p_findex;
+ int ht;
if (xp->xp_numfiles <= 0)
return NULL;
@@ -424,11 +426,50 @@ get_next_or_prev_match(
findex = xp->xp_numfiles;
--findex;
}
- else // mode == WILD_NEXT
+ else if (mode == WILD_NEXT)
++findex;
+ else if (mode == WILD_PAGEUP)
+ {
+ if (findex == 0)
+ // at the first entry, don't select any entries
+ 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
+ {
+ if (findex == xp->xp_numfiles - 1)
+ // at the last entry, don't select any entries
+ findex = -1;
+ else if (findex == -1)
+ // no entry is selected. select the first entry
+ findex = 0;
+ else
+ {
+ // go down by the pum height
+ ht = pum_get_height();
+ if (ht > 3)
+ ht -= 2;
+ findex += ht;
+ if (findex >= xp->xp_numfiles)
+ // few entries left, select the last entry
+ findex = xp->xp_numfiles - 1;
+ }
+ }
- // When wrapping around, return the original string, set findex to
- // -1.
+ // When wrapping around, return the original string, set findex to -1.
if (findex < 0)
{
if (orig_save == NULL)
@@ -585,7 +626,7 @@ find_longest_match(expand_T *xp, int options)
}
/*
- * Do wildcard expansion on the string 'str'.
+ * Do wildcard expansion on the string "str".
* Chars that should not be expanded must be preceded with a backslash.
* Return a pointer to allocated memory containing the new string.
* Return NULL for failure.
@@ -639,7 +680,8 @@ ExpandOne(
long_u len;
// first handle the case of using an old match
- if (mode == WILD_NEXT || mode == WILD_PREV)
+ if (mode == WILD_NEXT || mode == WILD_PREV
+ || mode == WILD_PAGEUP || mode == WILD_PAGEDOWN)
return get_next_or_prev_match(mode, xp, &findex, orig_save);
if (mode == WILD_CANCEL)