diff options
author | David Z. Chen <david.z.chen@outlook.com> | 2014-03-10 03:48:12 -0700 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-03-16 12:00:41 -0300 |
commit | baab23827194175e811cfaccd287e9438f1d1b6d (patch) | |
tree | 72d3d35fc2680149fdbcc32a9d068e6a7c821354 /src/popupmnu.c | |
parent | 8a6118ccaced623b9e6d854e3a41fbd9d6fc68df (diff) | |
download | rneovim-baab23827194175e811cfaccd287e9438f1d1b6d.tar.gz rneovim-baab23827194175e811cfaccd287e9438f1d1b6d.tar.bz2 rneovim-baab23827194175e811cfaccd287e9438f1d1b6d.zip |
Issue #311 - Clean up blowfish.c/h, charset.c/h, diff.c/h, digraph.c/h, garray.c/h, hashtab.c/h, popupmnu.c/h, sha256.c/h, version.c/h. Update uncrustify to move logical operators to the beginning of the line when splitting. Also, clean up arabic.c/h and farsi.c/h
Diffstat (limited to 'src/popupmnu.c')
-rw-r--r-- | src/popupmnu.c | 589 |
1 files changed, 322 insertions, 267 deletions
diff --git a/src/popupmnu.c b/src/popupmnu.c index 7ae9018e0c..a563095c95 100644 --- a/src/popupmnu.c +++ b/src/popupmnu.c @@ -1,15 +1,7 @@ -/* vi:set ts=8 sts=4 sw=4: - * - * VIM - Vi IMproved by Bram Moolenaar - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ - -/* - * popupmnu.c: Popup menu (PUM) - */ +/// @file popupmnu.c +/// +/// Popup menu (PUM) +// #include "vim.h" #include "popupmnu.h" #include "charset.h" @@ -22,40 +14,36 @@ #include "search.h" #include "window.h" -static pumitem_T *pum_array = NULL; /* items of displayed pum */ -static int pum_size; /* nr of items in "pum_array" */ -static int pum_selected; /* index of selected item or -1 */ -static int pum_first = 0; /* index of top item */ +static pumitem_T *pum_array = NULL; // items of displayed pum +static int pum_size; // nr of items in "pum_array" +static int pum_selected; // index of selected item or -1 +static int pum_first = 0; // index of top item -static int pum_height; /* nr of displayed pum items */ -static int pum_width; /* width of displayed pum items */ -static int pum_base_width; /* width of pum items base */ -static int pum_kind_width; /* width of pum items kind column */ -static int pum_scrollbar; /* TRUE when scrollbar present */ +static int pum_height; // nr of displayed pum items +static int pum_width; // width of displayed pum items +static int pum_base_width; // width of pum items base +static int pum_kind_width; // width of pum items kind column +static int pum_scrollbar; // TRUE when scrollbar present -static int pum_row; /* top row of pum */ -static int pum_col; /* left column of pum */ +static int pum_row; // top row of pum +static int pum_col; // left column of pum -static int pum_do_redraw = FALSE; /* do redraw anyway */ +static int pum_do_redraw = FALSE; // do redraw anyway static int pum_set_selected(int n, int repeat); #define PUM_DEF_HEIGHT 10 #define PUM_DEF_WIDTH 15 -/* - * Show the popup menu with items "array[size]". - * "array" must remain valid until pum_undisplay() is called! - * When possible the leftmost character is aligned with screen column "col". - * The menu appears above the screen line "row" or at "row" + "height" - 1. - */ -void -pum_display ( - pumitem_T *array, - int size, - int selected /* index of initially selected item, none if - out of range */ -) +/// Show the popup menu with items "array[size]". +/// "array" must remain valid until pum_undisplay() is called! +/// When possible the leftmost character is aligned with screen column "col". +/// The menu appears above the screen line "row" or at "row" + "height" - 1. +/// +/// @param array +/// @param size +/// @param selected index of initially selected item, none if out of range +void pum_display(pumitem_T *array, int size, int selected) { int w; int def_width; @@ -76,46 +64,50 @@ redo: kind_width = 0; extra_width = 0; - /* Pretend the pum is already there to avoid that must_redraw is set when - * 'cuc' is on. */ + // Pretend the pum is already there to avoid that must_redraw is set when + // 'cuc' is on. pum_array = (pumitem_T *)1; validate_cursor_col(); pum_array = NULL; row = curwin->w_wrow + W_WINROW(curwin); - if (firstwin->w_p_pvw) + if (firstwin->w_p_pvw) { top_clear = firstwin->w_height; - else + } else { top_clear = 0; + } - /* When the preview window is at the bottom stop just above it. Also - * avoid drawing over the status line so that it's clear there is a window - * boundary. */ - if (lastwin->w_p_pvw) + // When the preview window is at the bottom stop just above it. Also + // avoid drawing over the status line so that it's clear there is a window + // boundary. + if (lastwin->w_p_pvw) { above_row -= lastwin->w_height + lastwin->w_status_height + 1; + } - /* - * Figure out the size and position of the pum. - */ - if (size < PUM_DEF_HEIGHT) + // Figure out the size and position of the pum. + if (size < PUM_DEF_HEIGHT) { pum_height = size; - else + } else { pum_height = PUM_DEF_HEIGHT; - if (p_ph > 0 && pum_height > p_ph) + } + + if ((p_ph > 0) && (pum_height > p_ph)) { pum_height = p_ph; + } - /* Put the pum below "row" if possible. If there are few lines decide on - * where there is more room. */ - if (row + 2 >= above_row - pum_height - && row > (above_row - top_clear) / 2) { - /* pum above "row" */ + // Put the pum below "row" if possible. If there are few lines decide on + // where there is more room. + if ((row + 2 >= above_row - pum_height) + && (row > (above_row - top_clear) / 2)) { + // pum above "row" - /* Leave two lines of context if possible */ - if (curwin->w_wrow - curwin->w_cline_row >= 2) + // Leave two lines of context if possible + if (curwin->w_wrow - curwin->w_cline_row >= 2) { context_lines = 2; - else + } else { context_lines = curwin->w_wrow - curwin->w_cline_row; + } if (row >= size + context_lines) { pum_row = row - size - context_lines; @@ -124,125 +116,148 @@ redo: pum_row = 0; pum_height = row - context_lines; } - if (p_ph > 0 && pum_height > p_ph) { + + if ((p_ph > 0) && (pum_height > p_ph)) { pum_row += pum_height - p_ph; pum_height = p_ph; } - } else { - /* pum below "row" */ + } else { + // pum below "row" - /* Leave two lines of context if possible */ - if (curwin->w_cline_row + curwin->w_cline_height - curwin->w_wrow >= 3) + // Leave two lines of context if possible + if (curwin->w_cline_row + curwin->w_cline_height - curwin->w_wrow >= 3) { context_lines = 3; - else + } else { context_lines = curwin->w_cline_row + curwin->w_cline_height - curwin->w_wrow; + } pum_row = row + context_lines; - if (size > above_row - pum_row) + if (size > above_row - pum_row) { pum_height = above_row - pum_row; - else + } else { pum_height = size; - if (p_ph > 0 && pum_height > p_ph) + } + + if ((p_ph > 0) && (pum_height > p_ph)) { pum_height = p_ph; + } } - /* don't display when we only have room for one line */ - if (pum_height < 1 || (pum_height == 1 && size > 1)) + // don't display when we only have room for one line + if ((pum_height < 1) || ((pum_height == 1) && (size > 1))) { return; + } - /* If there is a preview window at the top avoid drawing over it. */ + // If there is a preview window at the top avoid drawing over it. if (firstwin->w_p_pvw - && pum_row < firstwin->w_height - && pum_height > firstwin->w_height + 4) { + && (pum_row < firstwin->w_height) + && (pum_height > firstwin->w_height + 4)) { pum_row += firstwin->w_height; pum_height -= firstwin->w_height; } - /* Compute the width of the widest match and the widest extra. */ + // Compute the width of the widest match and the widest extra. for (i = 0; i < size; ++i) { w = vim_strsize(array[i].pum_text); - if (max_width < w) + + if (max_width < w) { max_width = w; + } + if (array[i].pum_kind != NULL) { w = vim_strsize(array[i].pum_kind) + 1; - if (kind_width < w) + + if (kind_width < w) { kind_width = w; + } } + if (array[i].pum_extra != NULL) { w = vim_strsize(array[i].pum_extra) + 1; - if (extra_width < w) + + if (extra_width < w) { extra_width = w; + } } } pum_base_width = max_width; pum_kind_width = kind_width; - /* Calculate column */ - if (curwin->w_p_rl) + // Calculate column + if (curwin->w_p_rl) { col = W_WINCOL(curwin) + W_WIDTH(curwin) - curwin->w_wcol - 1; - else + } else { col = W_WINCOL(curwin) + curwin->w_wcol; + } - /* if there are more items than room we need a scrollbar */ + // if there are more items than room we need a scrollbar if (pum_height < size) { pum_scrollbar = 1; - ++max_width; - } else + max_width++; + } else { pum_scrollbar = 0; + } - if (def_width < max_width) + if (def_width < max_width) { def_width = max_width; + } - if (((col < Columns - PUM_DEF_WIDTH || col < Columns - max_width) + if ((((col < Columns - PUM_DEF_WIDTH) || (col < Columns - max_width)) && !curwin->w_p_rl) - || (curwin->w_p_rl && (col > PUM_DEF_WIDTH || col > max_width) - )) { - /* align pum column with "col" */ + || (curwin->w_p_rl && ((col > PUM_DEF_WIDTH) || (col > max_width)))) { + // align pum column with "col" pum_col = col; - - if (curwin->w_p_rl) + if (curwin->w_p_rl) { pum_width = pum_col - pum_scrollbar + 1; - else + } else { pum_width = Columns - pum_col - pum_scrollbar; + } - if (pum_width > max_width + kind_width + extra_width + 1 - && pum_width > PUM_DEF_WIDTH) { + if ((pum_width > max_width + kind_width + extra_width + 1) + && (pum_width > PUM_DEF_WIDTH)) { pum_width = max_width + kind_width + extra_width + 1; - if (pum_width < PUM_DEF_WIDTH) + + if (pum_width < PUM_DEF_WIDTH) { pum_width = PUM_DEF_WIDTH; + } } - } else if (Columns < def_width) { - /* not enough room, will use what we have */ - if (curwin->w_p_rl) + } else if (Columns < def_width) { + // not enough room, will use what we have + if (curwin->w_p_rl) { pum_col = Columns - 1; - else + } else { pum_col = 0; + } pum_width = Columns - 1; - } else { - if (max_width > PUM_DEF_WIDTH) - max_width = PUM_DEF_WIDTH; /* truncate */ - if (curwin->w_p_rl) + } else { + if (max_width > PUM_DEF_WIDTH) { + // truncate + max_width = PUM_DEF_WIDTH; + } + + if (curwin->w_p_rl) { pum_col = max_width - 1; - else + } else { pum_col = Columns - max_width; + } pum_width = max_width - pum_scrollbar; } pum_array = array; pum_size = size; - /* Set selected item and redraw. If the window size changed need to redo - * the positioning. Limit this to two times, when there is not much - * room the window size will keep changing. */ - if (pum_set_selected(selected, redo_count) && ++redo_count <= 2) + // Set selected item and redraw. If the window size changed need to redo + // the positioning. Limit this to two times, when there is not much + // room the window size will keep changing. + if (pum_set_selected(selected, redo_count) && (++redo_count <= 2)) { goto redo; + } } -/* - * Redraw the popup menu, using "pum_first" and "pum_selected". - */ -void pum_redraw(void) { +/// Redraw the popup menu, using "pum_first" and "pum_selected". +void pum_redraw(void) +{ int row = pum_row; int col; int attr_norm = highlight_attr[HLF_PNI]; @@ -252,22 +267,24 @@ void pum_redraw(void) { int attr; int i; int idx; - char_u *s; - char_u *p = NULL; + char_u *s; + char_u *p = NULL; int totwidth, width, w; int thumb_pos = 0; int thumb_heigth = 1; int round; int n; - /* Never display more than we have */ - if (pum_first > pum_size - pum_height) + // Never display more than we have + if (pum_first > pum_size - pum_height) { pum_first = pum_size - pum_height; + } if (pum_scrollbar) { thumb_heigth = pum_height * pum_height / pum_size; - if (thumb_heigth == 0) + if (thumb_heigth == 0) { thumb_heigth = 1; + } thumb_pos = (pum_first * (pum_height - thumb_heigth) + (pum_size - pum_height) / 2) / (pum_size - pum_height); @@ -277,155 +294,179 @@ void pum_redraw(void) { idx = i + pum_first; attr = (idx == pum_selected) ? attr_select : attr_norm; - /* prepend a space if there is room */ + // prepend a space if there is room if (curwin->w_p_rl) { - if (pum_col < W_WINCOL(curwin) + W_WIDTH(curwin) - 1) + if (pum_col < W_WINCOL(curwin) + W_WIDTH(curwin) - 1) { screen_putchar(' ', row, pum_col + 1, attr); - } else if (pum_col > 0) + } + } else if (pum_col > 0) { screen_putchar(' ', row, pum_col - 1, attr); + } - /* Display each entry, use two spaces for a Tab. - * Do this 3 times: For the main text, kind and extra info */ + // Display each entry, use two spaces for a Tab. + // Do this 3 times: For the main text, kind and extra info col = pum_col; totwidth = 0; + for (round = 1; round <= 3; ++round) { width = 0; s = NULL; + switch (round) { - case 1: p = pum_array[idx].pum_text; break; - case 2: p = pum_array[idx].pum_kind; break; - case 3: p = pum_array[idx].pum_extra; break; + case 1: + p = pum_array[idx].pum_text; + break; + + case 2: + p = pum_array[idx].pum_kind; + break; + + case 3: + p = pum_array[idx].pum_extra; + break; } - if (p != NULL) + + if (p != NULL) { for (;; mb_ptr_adv(p)) { - if (s == NULL) + if (s == NULL) { s = p; + } w = ptr2cells(p); - if (*p == NUL || *p == TAB || totwidth + w > pum_width) { - /* Display the text that fits or comes before a Tab. - * First convert it to printable characters. */ - char_u *st; + + if ((*p == NUL) || (*p == TAB) || (totwidth + w > pum_width)) { + // Display the text that fits or comes before a Tab. + // First convert it to printable characters. + char_u *st; int saved = *p; *p = NUL; st = transstr(s); *p = saved; + if (curwin->w_p_rl) { if (st != NULL) { char_u *rt = reverse_text(st); if (rt != NULL) { - char_u *rt_start = rt; + char_u *rt_start = rt; int size; size = vim_strsize(rt); + if (size > pum_width) { do { - size -= has_mbyte - ? (*mb_ptr2cells)(rt) : 1; + size -= has_mbyte ? (*mb_ptr2cells)(rt) : 1; mb_ptr_adv(rt); } while (size > pum_width); if (size < pum_width) { - /* Most left character requires - * 2-cells but only 1 cell is - * available on screen. Put a - * '<' on the left of the pum - * item */ + // Most left character requires 2-cells but only 1 cell + // is available on screen. Put a '<' on the left of the + // pum item *(--rt) = '<'; size++; } } - screen_puts_len(rt, (int)STRLEN(rt), - row, col - size + 1, attr); + screen_puts_len(rt, (int)STRLEN(rt), row, col - size + 1, + attr); vim_free(rt_start); } vim_free(st); } col -= width; - } else { + } else { if (st != NULL) { - screen_puts_len(st, (int)STRLEN(st), row, col, - attr); + screen_puts_len(st, (int)STRLEN(st), row, col, attr); vim_free(st); } col += width; } - if (*p != TAB) + if (*p != TAB) { break; + } - /* Display two spaces for a Tab. */ + // Display two spaces for a Tab. if (curwin->w_p_rl) { - screen_puts_len((char_u *)" ", 2, row, col - 1, - attr); + screen_puts_len((char_u *)" ", 2, row, col - 1, attr); col -= 2; } else { screen_puts_len((char_u *)" ", 2, row, col, attr); col += 2; } totwidth += 2; - s = NULL; /* start text at next char */ + // start text at next char + s = NULL; width = 0; - } else + } else { width += w; + } } + } - if (round > 1) + if (round > 1) { n = pum_kind_width + 1; - else + } else { n = 1; + } - /* Stop when there is nothing more to display. */ - if (round == 3 - || (round == 2 && pum_array[idx].pum_extra == NULL) - || (round == 1 && pum_array[idx].pum_kind == NULL - && pum_array[idx].pum_extra == NULL) - || pum_base_width + n >= pum_width) + // Stop when there is nothing more to display. + if ((round == 3) + || ((round == 2) + && (pum_array[idx].pum_extra == NULL)) + || ((round == 1) + && (pum_array[idx].pum_kind == NULL) + && (pum_array[idx].pum_extra == NULL)) + || (pum_base_width + n >= pum_width)) { break; + } + if (curwin->w_p_rl) { screen_fill(row, row + 1, pum_col - pum_base_width - n + 1, - col + 1, ' ', ' ', attr); + col + 1, ' ', ' ', attr); col = pum_col - pum_base_width - n + 1; } else { screen_fill(row, row + 1, col, pum_col + pum_base_width + n, - ' ', ' ', attr); + ' ', ' ', attr); col = pum_col + pum_base_width + n; } totwidth = pum_base_width + n; } - if (curwin->w_p_rl) - screen_fill(row, row + 1, pum_col - pum_width + 1, col + 1, ' ', - ' ', attr); - else - screen_fill(row, row + 1, col, pum_col + pum_width, ' ', ' ', - attr); + if (curwin->w_p_rl) { + screen_fill(row, row + 1, pum_col - pum_width + 1, col + 1, ' ', ' ', + attr); + } else { + screen_fill(row, row + 1, col, pum_col + pum_width, ' ', ' ', attr); + } + if (pum_scrollbar > 0) { - if (curwin->w_p_rl) + if (curwin->w_p_rl) { screen_putchar(' ', row, pum_col - pum_width, - i >= thumb_pos && i < thumb_pos + thumb_heigth - ? attr_thumb : attr_scroll); - else + i >= thumb_pos && i < thumb_pos + thumb_heigth + ? attr_thumb : attr_scroll); + } else { screen_putchar(' ', row, pum_col + pum_width, - i >= thumb_pos && i < thumb_pos + thumb_heigth - ? attr_thumb : attr_scroll); + i >= thumb_pos && i < thumb_pos + thumb_heigth + ? attr_thumb : attr_scroll); + } } - - ++row; + row++; } } -/* - * Set the index of the currently selected item. The menu will scroll when - * necessary. When "n" is out of range don't scroll. - * This may be repeated when the preview window is used: - * "repeat" == 0: open preview window normally - * "repeat" == 1: open preview window but don't set the size - * "repeat" == 2: don't open preview window - * Returns TRUE when the window was resized and the location of the popup menu - * must be recomputed. - */ +/// Set the index of the currently selected item. The menu will scroll when +/// necessary. When "n" is out of range don't scroll. +/// This may be repeated when the preview window is used: +/// "repeat" == 0: open preview window normally +/// "repeat" == 1: open preview window but don't set the size +/// "repeat" == 2: don't open preview window +/// +/// @param n +/// @param repeat +/// +/// @returns TRUE when the window was resized and the location of the popup +/// menu must be recomputed. static int pum_set_selected(int n, int repeat) { int resized = FALSE; @@ -433,100 +474,112 @@ static int pum_set_selected(int n, int repeat) pum_selected = n; - if (pum_selected >= 0 && pum_selected < pum_size) { + if ((pum_selected >= 0) && (pum_selected < pum_size)) { if (pum_first > pum_selected - 4) { - /* scroll down; when we did a jump it's probably a PageUp then - * scroll a whole page */ + // scroll down; when we did a jump it's probably a PageUp then + // scroll a whole page if (pum_first > pum_selected - 2) { pum_first -= pum_height - 2; - if (pum_first < 0) + if (pum_first < 0) { pum_first = 0; - else if (pum_first > pum_selected) + } else if (pum_first > pum_selected) { pum_first = pum_selected; - } else + } + } else { pum_first = pum_selected; - } else if (pum_first < pum_selected - pum_height + 5) { - /* scroll up; when we did a jump it's probably a PageDown then - * scroll a whole page */ + } + } else if (pum_first < pum_selected - pum_height + 5) { + // scroll up; when we did a jump it's probably a PageDown then + // scroll a whole page if (pum_first < pum_selected - pum_height + 1 + 2) { pum_first += pum_height - 2; - if (pum_first < pum_selected - pum_height + 1) + if (pum_first < pum_selected - pum_height + 1) { pum_first = pum_selected - pum_height + 1; - } else + } + } else { pum_first = pum_selected - pum_height + 1; + } } - /* Give a few lines of context when possible. */ - if (context > 3) + // Give a few lines of context when possible. + if (context > 3) { context = 3; + } + if (pum_height > 2) { if (pum_first > pum_selected - context) { - /* scroll down */ + // scroll down pum_first = pum_selected - context; - if (pum_first < 0) + + if (pum_first < 0) { pum_first = 0; - } else if (pum_first < pum_selected + context - pum_height + 1) { - /* scroll up */ + } + } else if (pum_first < pum_selected + context - pum_height + 1) { + // scroll up pum_first = pum_selected + context - pum_height + 1; } } - /* - * Show extra info in the preview window if there is something and - * 'completeopt' contains "preview". - * Skip this when tried twice already. - * Skip this also when there is not much room. - * NOTE: Be very careful not to sync undo! - */ - if (pum_array[pum_selected].pum_info != NULL - && Rows > 10 - && repeat <= 1 - && vim_strchr(p_cot, 'p') != NULL) { - win_T *curwin_save = curwin; + // Show extra info in the preview window if there is something and + // 'completeopt' contains "preview". + // Skip this when tried twice already. + // Skip this also when there is not much room. + // NOTE: Be very careful not to sync undo! + if ((pum_array[pum_selected].pum_info != NULL) + && (Rows > 10) + && (repeat <= 1) + && (vim_strchr(p_cot, 'p') != NULL)) { + win_T *curwin_save = curwin; int res = OK; - /* Open a preview window. 3 lines by default. Prefer - * 'previewheight' if set and smaller. */ + // Open a preview window. 3 lines by default. Prefer + // 'previewheight' if set and smaller. g_do_tagpreview = 3; - if (p_pvh > 0 && p_pvh < g_do_tagpreview) + + if ((p_pvh > 0) && (p_pvh < g_do_tagpreview)) { g_do_tagpreview = p_pvh; + } resized = prepare_tagpreview(FALSE); g_do_tagpreview = 0; if (curwin->w_p_pvw) { - if (curbuf->b_fname == NULL - && curbuf->b_p_bt[0] == 'n' && curbuf->b_p_bt[2] == 'f' - && curbuf->b_p_bh[0] == 'w') { - /* Already a "wipeout" buffer, make it empty. */ - while (!bufempty()) + if ((curbuf->b_fname == NULL) + && (curbuf->b_p_bt[0] == 'n') + && (curbuf->b_p_bt[2] == 'f') + && (curbuf->b_p_bh[0] == 'w')) { + // Already a "wipeout" buffer, make it empty. + while (!bufempty()) { ml_delete((linenr_T)1, FALSE); - } else { - /* Don't want to sync undo in the current buffer. */ - ++no_u_sync; + } + } else { + // Don't want to sync undo in the current buffer. + no_u_sync++; res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0, NULL); - --no_u_sync; + no_u_sync--; + if (res == OK) { - /* Edit a new, empty buffer. Set options for a "wipeout" - * buffer. */ + // Edit a new, empty buffer. Set options for a "wipeout" + // buffer. set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL); set_option_value((char_u *)"bt", 0L, - (char_u *)"nofile", OPT_LOCAL); + (char_u *)"nofile", OPT_LOCAL); set_option_value((char_u *)"bh", 0L, - (char_u *)"wipe", OPT_LOCAL); + (char_u *)"wipe", OPT_LOCAL); set_option_value((char_u *)"diff", 0L, - NULL, OPT_LOCAL); + NULL, OPT_LOCAL); } } + if (res == OK) { - char_u *p, *e; + char_u *p, *e; linenr_T lnum = 0; - for (p = pum_array[pum_selected].pum_info; *p != NUL; ) { + for (p = pum_array[pum_selected].pum_info; *p != NUL;) { e = vim_strchr(p, '\n'); if (e == NULL) { ml_append(lnum++, p, 0, FALSE); break; - } else { + } else { *e = NUL; ml_append(lnum++, p, (int)(e - p + 1), FALSE); *e = '\n'; @@ -534,11 +587,13 @@ static int pum_set_selected(int n, int repeat) } } - /* Increase the height of the preview window to show the - * text, but no more than 'previewheight' lines. */ + // Increase the height of the preview window to show the + // text, but no more than 'previewheight' lines. if (repeat == 0) { - if (lnum > p_pvh) + if (lnum > p_pvh) { lnum = p_pvh; + } + if (curwin->w_height < lnum) { win_setheight((int)lnum); resized = TRUE; @@ -550,31 +605,32 @@ static int pum_set_selected(int n, int repeat) curwin->w_cursor.lnum = 1; curwin->w_cursor.col = 0; - if (curwin != curwin_save && win_valid(curwin_save)) { - /* Return cursor to where we were */ + if ((curwin != curwin_save) && win_valid(curwin_save)) { + // Return cursor to where we were validate_cursor(); redraw_later(SOME_VALID); - /* When the preview window was resized we need to - * update the view on the buffer. Only go back to - * the window when needed, otherwise it will always be - * redraw. */ + // When the preview window was resized we need to + // update the view on the buffer. Only go back to + // the window when needed, otherwise it will always be + // redraw. if (resized) { win_enter(curwin_save, TRUE); update_topline(); } - /* Update the screen before drawing the popup menu. - * Enable updating the status lines. */ + // Update the screen before drawing the popup menu. + // Enable updating the status lines. pum_do_redraw = TRUE; update_screen(0); pum_do_redraw = FALSE; - if (!resized && win_valid(curwin_save)) + if (!resized && win_valid(curwin_save)) { win_enter(curwin_save, TRUE); + } - /* May need to update the screen again when there are - * autocommands involved. */ + // May need to update the screen again when there are + // autocommands involved. pum_do_redraw = TRUE; update_screen(0); pum_do_redraw = FALSE; @@ -584,43 +640,42 @@ static int pum_set_selected(int n, int repeat) } } - if (!resized) + if (!resized) { pum_redraw(); + } return resized; } -/* - * Undisplay the popup menu (later). - */ -void pum_undisplay(void) { +/// Undisplay the popup menu (later). +void pum_undisplay(void) +{ pum_array = NULL; redraw_all_later(SOME_VALID); redraw_tabline = TRUE; status_redraw_all(); } -/* - * Clear the popup menu. Currently only resets the offset to the first - * displayed item. - */ -void pum_clear(void) { +/// Clear the popup menu. Currently only resets the offset to the first +/// displayed item. +void pum_clear(void) +{ pum_first = 0; } -/* - * Return TRUE if the popup menu is displayed. - * Overruled when "pum_do_redraw" is set, used to redraw the status lines. - */ -int pum_visible(void) { +/// Overruled when "pum_do_redraw" is set, used to redraw the status lines. +/// +/// @return TRUE if the popup menu is displayed. +int pum_visible(void) +{ return !pum_do_redraw && pum_array != NULL; } -/* - * Return the height of the popup menu, the number of entries visible. - * Only valid when pum_visible() returns TRUE! - */ -int pum_get_height(void) { +/// Gets the height of the menu. +/// +/// @return the height of the popup menu, the number of entries visible. +/// Only valid when pum_visible() returns TRUE! +int pum_get_height(void) +{ return pum_height; } - |