diff src/cmdexpand.c @ 28109:06535d568f74 v8.2.4579

patch 8.2.4579: cannot use page-up and page-down in the cmdline popup menu Commit: https://github.com/vim/vim/commit/5cffa8df7e3c28681b9e5deef6df395784359b6b Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Wed Mar 16 13:33:53 2022 +0000 patch 8.2.4579: cannot use page-up and page-down in the cmdline popup menu 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)
author Bram Moolenaar <Bram@vim.org>
date Wed, 16 Mar 2022 14:45:04 +0100
parents 554f493902ea
children 130f4082a13d
line wrap: on
line diff
--- 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;
-
-    // When wrapping around, return the original string, set findex to
-    // -1.
+    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.
     if (findex < 0)
     {
 	if (orig_save == NULL)
@@ -585,7 +626,7 @@ find_longest_match(expand_T *xp, int opt
 }
 
 /*
- * 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)