patch 9.1.1109: cmdexpand.c hard to read Commit: https://github.com/vim/vim/commit/977561a7198b5d31a17b852e332704025c2dbdc8 Author: glepnir <glephun...@gmail.com> Date: Thu Feb 13 20:48:56 2025 +0100
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 <glephun...@gmail.com> Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/src/cmdexpand.c b/src/cmdexpand.c index 3ceb6c73e..bd9a410ac 100644 --- a/src/cmdexpand.c +++ b/src/cmdexpand.c @@ -373,10 +373,7 @@ cmdline_pum_create( columns += vim_strsize(showmatches_gettail(matches[0])); columns -= vim_strsize(matches[0]); } - if (columns >= compl_startcol) - compl_startcol = 0; - else - compl_startcol -= columns; + compl_startcol = MAX(0, compl_startcol - columns); // no default selection compl_selected = -1; @@ -735,94 +732,84 @@ win_redr_status_matches( * in "xp->xp_selected" */ static char_u * -get_next_or_prev_match( - int mode, - expand_T *xp) +get_next_or_prev_match(int mode, expand_T *xp) { - int findex = xp->xp_selected; - int ht; + int findex = xp->xp_selected; + int ht; + // When no files found, return NULL if (xp->xp_numfiles <= 0) return NULL; if (mode == WILD_PREV) { + // Select last file if at start if (findex == -1) findex = xp->xp_numfiles; --findex; } 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; - } + // Select next file + findex = findex + 1; } - else // mode == WILD_PAGEDOWN + else // WILD_PAGEDOWN or WILD_PAGEUP { - 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 + // Get the height of popup menu (used for both PAGEUP and PAGEDOWN) + ht = pum_get_height(); + if (ht > 3) + ht -= 2; + + if (mode == WILD_PAGEUP) { - // 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 + 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 + 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. - if (findex < 0) + // Handle wrapping around + if (findex < 0 || findex >= xp->xp_numfiles) { - if (xp->xp_orig == NULL) - findex = xp->xp_numfiles - 1; - else + // If original string exists, return to it when wrapping around + if (xp->xp_orig != NULL) findex = -1; - } - if (findex >= xp->xp_numfiles) - { - if (xp->xp_orig == NULL) - findex = 0; else - findex = -1; + // Wrap around to opposite end + findex = (findex < 0) ? xp->xp_numfiles - 1 : 0; } + + // Display matches on screen if (compl_match_array) { compl_selected = findex; cmdline_pum_display(); } else if (p_wmnu) - win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, - findex, cmd_showtail); - xp->xp_selected = findex; - - if (findex == -1) - return vim_strsave(xp->xp_orig); + win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, findex, + cmd_showtail); - return vim_strsave(xp->xp_files[findex]); + xp->xp_selected = findex; + // Return the original string or the selected match + return vim_strsave(findex == -1 ? xp->xp_orig : xp->xp_files[findex]); } /* diff --git a/src/version.c b/src/version.c index 8854292e1..1745ef3db 100644 --- a/src/version.c +++ b/src/version.c @@ -704,6 +704,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1109, /**/ 1108, /**/ -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1tifNV-0071rk-UB%40256bit.org.