diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-01-15 07:59:24 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-15 07:59:24 +0800 |
commit | fe17cd50fbff5ebed44b6b0d46f3dc933696c1da (patch) | |
tree | d0fb1562b4281efd1f9b3453c649d625321ebcb3 /src/nvim/cmdexpand.c | |
parent | 4c8d707a5e28805a1211726817576cd1bb32ecf7 (diff) | |
parent | 940643aa331e31678467c770b77808e0b4240b34 (diff) | |
download | rneovim-fe17cd50fbff5ebed44b6b0d46f3dc933696c1da.tar.gz rneovim-fe17cd50fbff5ebed44b6b0d46f3dc933696c1da.tar.bz2 rneovim-fe17cd50fbff5ebed44b6b0d46f3dc933696c1da.zip |
Merge pull request #21807 from zeertzjq/vim-8.2.4579
vim-patch:8.2.{4481,4579,4585}: PageUp/PageDown for cmdline pum
Diffstat (limited to 'src/nvim/cmdexpand.c')
-rw-r--r-- | src/nvim/cmdexpand.c | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 422649b67b..a1f15fabb6 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -217,7 +217,9 @@ int nextwild(expand_T *xp, int type, int options, bool escape) assert(ccline->cmdpos >= i); xp->xp_pattern_len = (size_t)ccline->cmdpos - (size_t)i; - if (type == WILD_NEXT || type == WILD_PREV || type == WILD_PUM_WANT) { + if (type == WILD_NEXT || type == WILD_PREV + || type == WILD_PAGEUP || type == WILD_PAGEDOWN + || type == WILD_PUM_WANT) { // Get next/previous match for a previous expanded pattern. p2 = ExpandOne(xp, NULL, NULL, 0, type); } else { @@ -593,6 +595,44 @@ static char *get_next_or_prev_match(int mode, expand_T *xp, int *p_findex, char 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 + int ht = pum_get_height(); + if (ht > 3) { + ht -= 2; + } + findex -= ht; + if (findex < 0) { + // few entries left, select the first entry + findex = 0; + } + } + } else if (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 + int 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; + } + } } else { // mode == WILD_PUM_WANT assert(pum_want.active); findex = pum_want.item; @@ -770,7 +810,9 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) int i; // first handle the case of using an old match - if (mode == WILD_NEXT || mode == WILD_PREV || mode == WILD_PUM_WANT) { + if (mode == WILD_NEXT || mode == WILD_PREV + || mode == WILD_PAGEUP || mode == WILD_PAGEDOWN + || mode == WILD_PUM_WANT) { return get_next_or_prev_match(mode, xp, &findex, orig_save); } |