Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
28108:00e653cb7b22 | 28109:06535d568f74 |
---|---|
222 out_flush(); | 222 out_flush(); |
223 | 223 |
224 i = (int)(xp->xp_pattern - ccline->cmdbuff); | 224 i = (int)(xp->xp_pattern - ccline->cmdbuff); |
225 xp->xp_pattern_len = ccline->cmdpos - i; | 225 xp->xp_pattern_len = ccline->cmdpos - i; |
226 | 226 |
227 if (type == WILD_NEXT || type == WILD_PREV) | 227 if (type == WILD_NEXT || type == WILD_PREV |
228 || type == WILD_PAGEUP || type == WILD_PAGEDOWN) | |
228 { | 229 { |
229 // Get next/previous match for a previous expanded pattern. | 230 // Get next/previous match for a previous expanded pattern. |
230 p2 = ExpandOne(xp, NULL, NULL, 0, type); | 231 p2 = ExpandOne(xp, NULL, NULL, 0, type); |
231 } | 232 } |
232 else | 233 else |
402 } | 403 } |
403 #endif | 404 #endif |
404 | 405 |
405 /* | 406 /* |
406 * Get the next or prev cmdline completion match. The index of the match is set | 407 * Get the next or prev cmdline completion match. The index of the match is set |
407 * in 'p_findex' | 408 * in "p_findex" |
408 */ | 409 */ |
409 static char_u * | 410 static char_u * |
410 get_next_or_prev_match( | 411 get_next_or_prev_match( |
411 int mode, | 412 int mode, |
412 expand_T *xp, | 413 expand_T *xp, |
413 int *p_findex, | 414 int *p_findex, |
414 char_u *orig_save) | 415 char_u *orig_save) |
415 { | 416 { |
416 int findex = *p_findex; | 417 int findex = *p_findex; |
418 int ht; | |
417 | 419 |
418 if (xp->xp_numfiles <= 0) | 420 if (xp->xp_numfiles <= 0) |
419 return NULL; | 421 return NULL; |
420 | 422 |
421 if (mode == WILD_PREV) | 423 if (mode == WILD_PREV) |
422 { | 424 { |
423 if (findex == -1) | 425 if (findex == -1) |
424 findex = xp->xp_numfiles; | 426 findex = xp->xp_numfiles; |
425 --findex; | 427 --findex; |
426 } | 428 } |
427 else // mode == WILD_NEXT | 429 else if (mode == WILD_NEXT) |
428 ++findex; | 430 ++findex; |
429 | 431 else if (mode == WILD_PAGEUP) |
430 // When wrapping around, return the original string, set findex to | 432 { |
431 // -1. | 433 if (findex == 0) |
434 // at the first entry, don't select any entries | |
435 findex = -1; | |
436 else if (findex == -1) | |
437 // no entry is selected. select the last entry | |
438 findex = xp->xp_numfiles - 1; | |
439 else | |
440 { | |
441 // go up by the pum height | |
442 ht = pum_get_height(); | |
443 if (ht > 3) | |
444 ht -= 2; | |
445 findex -= ht; | |
446 if (findex < 0) | |
447 // few entries left, select the first entry | |
448 findex = 0; | |
449 } | |
450 } | |
451 else // mode == WILD_PAGEDOWN | |
452 { | |
453 if (findex == xp->xp_numfiles - 1) | |
454 // at the last entry, don't select any entries | |
455 findex = -1; | |
456 else if (findex == -1) | |
457 // no entry is selected. select the first entry | |
458 findex = 0; | |
459 else | |
460 { | |
461 // go down by the pum height | |
462 ht = pum_get_height(); | |
463 if (ht > 3) | |
464 ht -= 2; | |
465 findex += ht; | |
466 if (findex >= xp->xp_numfiles) | |
467 // few entries left, select the last entry | |
468 findex = xp->xp_numfiles - 1; | |
469 } | |
470 } | |
471 | |
472 // When wrapping around, return the original string, set findex to -1. | |
432 if (findex < 0) | 473 if (findex < 0) |
433 { | 474 { |
434 if (orig_save == NULL) | 475 if (orig_save == NULL) |
435 findex = xp->xp_numfiles - 1; | 476 findex = xp->xp_numfiles - 1; |
436 else | 477 else |
583 | 624 |
584 return ss; | 625 return ss; |
585 } | 626 } |
586 | 627 |
587 /* | 628 /* |
588 * Do wildcard expansion on the string 'str'. | 629 * Do wildcard expansion on the string "str". |
589 * Chars that should not be expanded must be preceded with a backslash. | 630 * Chars that should not be expanded must be preceded with a backslash. |
590 * Return a pointer to allocated memory containing the new string. | 631 * Return a pointer to allocated memory containing the new string. |
591 * Return NULL for failure. | 632 * Return NULL for failure. |
592 * | 633 * |
593 * "orig" is the originally expanded string, copied to allocated memory. It | 634 * "orig" is the originally expanded string, copied to allocated memory. It |
637 int orig_saved = FALSE; | 678 int orig_saved = FALSE; |
638 int i; | 679 int i; |
639 long_u len; | 680 long_u len; |
640 | 681 |
641 // first handle the case of using an old match | 682 // first handle the case of using an old match |
642 if (mode == WILD_NEXT || mode == WILD_PREV) | 683 if (mode == WILD_NEXT || mode == WILD_PREV |
684 || mode == WILD_PAGEUP || mode == WILD_PAGEDOWN) | |
643 return get_next_or_prev_match(mode, xp, &findex, orig_save); | 685 return get_next_or_prev_match(mode, xp, &findex, orig_save); |
644 | 686 |
645 if (mode == WILD_CANCEL) | 687 if (mode == WILD_CANCEL) |
646 ss = vim_strsave(orig_save ? orig_save : (char_u *)""); | 688 ss = vim_strsave(orig_save ? orig_save : (char_u *)""); |
647 else if (mode == WILD_APPLY) | 689 else if (mode == WILD_APPLY) |