blob: ea52d8004369a26ff6528e54951a6a71a44054c4 [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar4b779472005-10-04 09:12:31 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
Bram Moolenaar30e8e732019-09-27 13:08:36 +020011 * popupmenu.c: Popup menu (PUM)
Bram Moolenaar4b779472005-10-04 09:12:31 +000012 */
13#include "vim.h"
14
Bram Moolenaar63d9e732019-12-05 21:10:38 +010015static pumitem_T *pum_array = NULL; // items of displayed pum
16static int pum_size; // nr of items in "pum_array"
17static int pum_selected; // index of selected item or -1
18static int pum_first = 0; // index of top item
Bram Moolenaar4b779472005-10-04 09:12:31 +000019
Bram Moolenaarae654382019-01-17 21:09:05 +010020static int call_update_screen = FALSE;
21
Bram Moolenaar63d9e732019-12-05 21:10:38 +010022static int pum_height; // nr of displayed pum items
23static int pum_width; // width of displayed pum items
24static int pum_base_width; // width of pum items base
25static int pum_kind_width; // width of pum items kind column
26static int pum_extra_width; // width of extra stuff
27static int pum_scrollbar; // TRUE when scrollbar present
Bram Moolenaar4b779472005-10-04 09:12:31 +000028
Bram Moolenaar63d9e732019-12-05 21:10:38 +010029static int pum_row; // top row of pum
30static int pum_col; // left column of pum
Bram Moolenaar4b779472005-10-04 09:12:31 +000031
Bram Moolenaar0e6e1792018-06-17 17:10:59 +020032static win_T *pum_window = NULL;
Bram Moolenaar491ac282018-06-17 14:47:55 +020033static int pum_win_row;
34static int pum_win_height;
35static int pum_win_col;
36static int pum_win_wcol;
37static int pum_win_width;
38
Bram Moolenaar04357fb2019-12-10 21:50:56 +010039// Some parts are not updated when a popup menu is visible. Setting this flag
40// makes pum_visible() return FALSE even when there is a popup menu.
41static int pum_pretend_not_visible = FALSE;
42
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010043static int pum_set_selected(int n, int repeat);
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +000044
Bram Moolenaar4b779472005-10-04 09:12:31 +000045#define PUM_DEF_HEIGHT 10
Bram Moolenaar4b779472005-10-04 09:12:31 +000046
Bram Moolenaar51b0f372017-11-18 18:52:04 +010047 static void
48pum_compute_size(void)
49{
50 int i;
51 int w;
52
Bram Moolenaar63d9e732019-12-05 21:10:38 +010053 // Compute the width of the widest match and the widest extra.
Bram Moolenaar51b0f372017-11-18 18:52:04 +010054 pum_base_width = 0;
55 pum_kind_width = 0;
56 pum_extra_width = 0;
57 for (i = 0; i < pum_size; ++i)
58 {
Bram Moolenaard58a6622020-05-02 14:52:57 +020059 if (pum_array[i].pum_text != NULL)
60 {
61 w = vim_strsize(pum_array[i].pum_text);
62 if (pum_base_width < w)
63 pum_base_width = w;
64 }
Bram Moolenaar51b0f372017-11-18 18:52:04 +010065 if (pum_array[i].pum_kind != NULL)
66 {
67 w = vim_strsize(pum_array[i].pum_kind) + 1;
68 if (pum_kind_width < w)
69 pum_kind_width = w;
70 }
71 if (pum_array[i].pum_extra != NULL)
72 {
73 w = vim_strsize(pum_array[i].pum_extra) + 1;
74 if (pum_extra_width < w)
75 pum_extra_width = w;
76 }
77 }
78}
79
Bram Moolenaar4b779472005-10-04 09:12:31 +000080/*
81 * Show the popup menu with items "array[size]".
82 * "array" must remain valid until pum_undisplay() is called!
Bram Moolenaar2b10bcb2018-02-24 21:25:44 +010083 * When possible the leftmost character is aligned with cursor column.
Bram Moolenaar4b779472005-10-04 09:12:31 +000084 * The menu appears above the screen line "row" or at "row" + "height" - 1.
85 */
86 void
Bram Moolenaar05540972016-01-30 20:31:25 +010087pum_display(
88 pumitem_T *array,
89 int size,
Bram Moolenaar63d9e732019-12-05 21:10:38 +010090 int selected) // index of initially selected item, none if
91 // out of range
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +000092{
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +000093 int def_width;
94 int max_width;
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000095 int context_lines;
Bram Moolenaar2b10bcb2018-02-24 21:25:44 +010096 int cursor_col;
Bram Moolenaar91e44a32016-11-04 20:08:52 +010097 int above_row;
98 int below_row;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000099 int redo_count = 0;
Bram Moolenaar4033c552017-09-16 20:54:51 +0200100#if defined(FEAT_QUICKFIX)
Bram Moolenaar91e44a32016-11-04 20:08:52 +0100101 win_T *pvwin;
Bram Moolenaaraab33832016-11-04 22:08:29 +0100102#endif
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +0100103#ifdef FEAT_RIGHTLEFT
Bram Moolenaar24959102022-05-07 20:01:16 +0100104 int right_left = State == MODE_CMDLINE ? FALSE : curwin->w_p_rl;
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +0100105#endif
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000106
Bram Moolenaara5e66212017-09-29 22:42:33 +0200107 do
108 {
Bram Moolenaar42443c72018-02-10 18:28:52 +0100109 def_width = p_pw;
Bram Moolenaara5e66212017-09-29 22:42:33 +0200110 above_row = 0;
111 below_row = cmdline_row;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000112
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100113 // Pretend the pum is already there to avoid that must_redraw is set
114 // when 'cuc' is on.
Bram Moolenaara5e66212017-09-29 22:42:33 +0200115 pum_array = (pumitem_T *)1;
116 validate_cursor_col();
117 pum_array = NULL;
Bram Moolenaar1e607892006-03-13 22:15:53 +0000118
Bram Moolenaar491ac282018-06-17 14:47:55 +0200119 // Remember the essential parts of the window position and size, so we
120 // can decide when to reposition the popup menu.
Bram Moolenaar0e6e1792018-06-17 17:10:59 +0200121 pum_window = curwin;
Bram Moolenaar24959102022-05-07 20:01:16 +0100122 if (State == MODE_CMDLINE)
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +0000123 // cmdline completion popup menu
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +0000124 pum_win_row = cmdline_row;
125 else
126 pum_win_row = curwin->w_wrow + W_WINROW(curwin);
Bram Moolenaar491ac282018-06-17 14:47:55 +0200127 pum_win_height = curwin->w_height;
128 pum_win_col = curwin->w_wincol;
129 pum_win_wcol = curwin->w_wcol;
130 pum_win_width = curwin->w_width;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000131
Bram Moolenaar4033c552017-09-16 20:54:51 +0200132#if defined(FEAT_QUICKFIX)
Bram Moolenaara5e66212017-09-29 22:42:33 +0200133 FOR_ALL_WINDOWS(pvwin)
134 if (pvwin->w_p_pvw)
135 break;
136 if (pvwin != NULL)
137 {
138 if (W_WINROW(pvwin) < W_WINROW(curwin))
139 above_row = W_WINROW(pvwin) + pvwin->w_height;
140 else if (W_WINROW(pvwin) > W_WINROW(curwin) + curwin->w_height)
141 below_row = W_WINROW(pvwin);
142 }
Bram Moolenaar0106e3d2016-02-23 18:55:43 +0100143#endif
Bram Moolenaarefd2bf12006-03-16 21:41:35 +0000144
Bram Moolenaara5e66212017-09-29 22:42:33 +0200145 /*
146 * Figure out the size and position of the pum.
147 */
148 if (size < PUM_DEF_HEIGHT)
Bram Moolenaar4b779472005-10-04 09:12:31 +0000149 pum_height = size;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000150 else
Bram Moolenaara5e66212017-09-29 22:42:33 +0200151 pum_height = PUM_DEF_HEIGHT;
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +0000152 if (p_ph > 0 && pum_height > p_ph)
153 pum_height = p_ph;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000154
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100155 // Put the pum below "pum_win_row" if possible. If there are few lines
156 // decide on where there is more room.
Bram Moolenaar491ac282018-06-17 14:47:55 +0200157 if (pum_win_row + 2 >= below_row - pum_height
158 && pum_win_row - above_row > (below_row - above_row) / 2)
Bram Moolenaara5e66212017-09-29 22:42:33 +0200159 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100160 // pum above "pum_win_row"
Bram Moolenaara5e66212017-09-29 22:42:33 +0200161
Bram Moolenaar24959102022-05-07 20:01:16 +0100162 if (State == MODE_CMDLINE)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +0100163 // for cmdline pum, no need for context lines
164 context_lines = 0;
Bram Moolenaara5e66212017-09-29 22:42:33 +0200165 else
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +0100166 {
167 // Leave two lines of context if possible
168 if (curwin->w_wrow - curwin->w_cline_row >= 2)
169 context_lines = 2;
170 else
171 context_lines = curwin->w_wrow - curwin->w_cline_row;
172 }
Bram Moolenaara5e66212017-09-29 22:42:33 +0200173
Bram Moolenaar491ac282018-06-17 14:47:55 +0200174 if (pum_win_row >= size + context_lines)
Bram Moolenaara5e66212017-09-29 22:42:33 +0200175 {
Bram Moolenaar491ac282018-06-17 14:47:55 +0200176 pum_row = pum_win_row - size - context_lines;
Bram Moolenaara5e66212017-09-29 22:42:33 +0200177 pum_height = size;
178 }
179 else
180 {
181 pum_row = 0;
Bram Moolenaar491ac282018-06-17 14:47:55 +0200182 pum_height = pum_win_row - context_lines;
Bram Moolenaara5e66212017-09-29 22:42:33 +0200183 }
184 if (p_ph > 0 && pum_height > p_ph)
185 {
186 pum_row += pum_height - p_ph;
187 pum_height = p_ph;
188 }
189 }
190 else
191 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100192 // pum below "pum_win_row"
Bram Moolenaara5e66212017-09-29 22:42:33 +0200193
Bram Moolenaar24959102022-05-07 20:01:16 +0100194 if (State == MODE_CMDLINE)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +0100195 // for cmdline pum, no need for context lines
196 context_lines = 0;
Bram Moolenaara5e66212017-09-29 22:42:33 +0200197 else
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +0100198 {
199 // Leave two lines of context if possible
200 validate_cheight();
201 if (curwin->w_cline_row
202 + curwin->w_cline_height - curwin->w_wrow >= 3)
203 context_lines = 3;
204 else
205 context_lines = curwin->w_cline_row
206 + curwin->w_cline_height - curwin->w_wrow;
207 }
Bram Moolenaara5e66212017-09-29 22:42:33 +0200208
Bram Moolenaar491ac282018-06-17 14:47:55 +0200209 pum_row = pum_win_row + context_lines;
Bram Moolenaara5e66212017-09-29 22:42:33 +0200210 if (size > below_row - pum_row)
211 pum_height = below_row - pum_row;
212 else
213 pum_height = size;
214 if (p_ph > 0 && pum_height > p_ph)
215 pum_height = p_ph;
216 }
217
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100218 // don't display when we only have room for one line
Bram Moolenaara5e66212017-09-29 22:42:33 +0200219 if (pum_height < 1 || (pum_height == 1 && size > 1))
220 return;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000221
Bram Moolenaar4033c552017-09-16 20:54:51 +0200222#if defined(FEAT_QUICKFIX)
Bram Moolenaar614ab8a2018-12-01 11:59:00 +0100223 // If there is a preview window above avoid drawing over it.
224 if (pvwin != NULL && pum_row < above_row && pum_height > above_row)
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000225 {
Bram Moolenaar614ab8a2018-12-01 11:59:00 +0100226 pum_row = above_row;
227 pum_height = pum_win_row - above_row;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000228 }
Bram Moolenaara5e66212017-09-29 22:42:33 +0200229#endif
230
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100231 pum_array = array;
232 pum_size = size;
233 pum_compute_size();
234 max_width = pum_base_width;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000235
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100236 // Calculate column
Bram Moolenaar24959102022-05-07 20:01:16 +0100237 if (State == MODE_CMDLINE)
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +0000238 // cmdline completion popup menu
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +0000239 cursor_col = cmdline_compl_startcol();
240 else
Bram Moolenaarabc97732007-08-08 20:49:37 +0000241#ifdef FEAT_RIGHTLEFT
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +0100242 if (right_left)
Bram Moolenaar2b10bcb2018-02-24 21:25:44 +0100243 cursor_col = curwin->w_wincol + curwin->w_width
244 - curwin->w_wcol - 1;
Bram Moolenaarabc97732007-08-08 20:49:37 +0000245 else
246#endif
Bram Moolenaar2b10bcb2018-02-24 21:25:44 +0100247 cursor_col = curwin->w_wincol + curwin->w_wcol;
Bram Moolenaarabc97732007-08-08 20:49:37 +0000248
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100249 // if there are more items than room we need a scrollbar
Bram Moolenaara5e66212017-09-29 22:42:33 +0200250 if (pum_height < size)
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000251 {
Bram Moolenaara5e66212017-09-29 22:42:33 +0200252 pum_scrollbar = 1;
253 ++max_width;
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000254 }
Bram Moolenaarabc97732007-08-08 20:49:37 +0000255 else
Bram Moolenaara5e66212017-09-29 22:42:33 +0200256 pum_scrollbar = 0;
257
258 if (def_width < max_width)
259 def_width = max_width;
260
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +0100261 if (((cursor_col < Columns - p_pw || cursor_col < Columns - max_width)
Bram Moolenaarabc97732007-08-08 20:49:37 +0000262#ifdef FEAT_RIGHTLEFT
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +0100263 && !right_left)
264 || (right_left && (cursor_col > p_pw || cursor_col > max_width)
Bram Moolenaarabc97732007-08-08 20:49:37 +0000265#endif
Bram Moolenaara5e66212017-09-29 22:42:33 +0200266 ))
267 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100268 // align pum with "cursor_col"
Bram Moolenaar2b10bcb2018-02-24 21:25:44 +0100269 pum_col = cursor_col;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000270
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100271 // start with the maximum space available
Bram Moolenaara5e66212017-09-29 22:42:33 +0200272#ifdef FEAT_RIGHTLEFT
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +0100273 if (right_left)
Bram Moolenaara5e66212017-09-29 22:42:33 +0200274 pum_width = pum_col - pum_scrollbar + 1;
275 else
276#endif
277 pum_width = Columns - pum_col - pum_scrollbar;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000278
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100279 if (pum_width > max_width + pum_kind_width + pum_extra_width + 1
Bram Moolenaar42443c72018-02-10 18:28:52 +0100280 && pum_width > p_pw)
Bram Moolenaara5e66212017-09-29 22:42:33 +0200281 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100282 // the width is more than needed for the items, make it
283 // narrower
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100284 pum_width = max_width + pum_kind_width + pum_extra_width + 1;
Bram Moolenaar42443c72018-02-10 18:28:52 +0100285 if (pum_width < p_pw)
286 pum_width = p_pw;
Bram Moolenaara5e66212017-09-29 22:42:33 +0200287 }
Bram Moolenaar2b10bcb2018-02-24 21:25:44 +0100288 else if (((cursor_col > p_pw || cursor_col > max_width)
Bram Moolenaara8f04aa2018-02-10 15:36:55 +0100289#ifdef FEAT_RIGHTLEFT
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +0100290 && !right_left)
291 || (right_left && (cursor_col < Columns - p_pw
Bram Moolenaar2b10bcb2018-02-24 21:25:44 +0100292 || cursor_col < Columns - max_width)
Bram Moolenaara8f04aa2018-02-10 15:36:55 +0100293#endif
294 ))
295 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100296 // align pum edge with "cursor_col"
Bram Moolenaara8f04aa2018-02-10 15:36:55 +0100297#ifdef FEAT_RIGHTLEFT
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +0100298 if (right_left
Bram Moolenaarbb008dd2018-02-24 18:59:55 +0100299 && W_ENDCOL(curwin) < max_width + pum_scrollbar + 1)
Bram Moolenaara8f04aa2018-02-10 15:36:55 +0100300 {
Bram Moolenaar2b10bcb2018-02-24 21:25:44 +0100301 pum_col = cursor_col + max_width + pum_scrollbar + 1;
Bram Moolenaara8f04aa2018-02-10 15:36:55 +0100302 if (pum_col >= Columns)
303 pum_col = Columns - 1;
304 }
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +0100305 else if (!right_left)
Bram Moolenaara8f04aa2018-02-10 15:36:55 +0100306#endif
307 {
Bram Moolenaar2b10bcb2018-02-24 21:25:44 +0100308 if (curwin->w_wincol > Columns - max_width - pum_scrollbar
309 && max_width <= p_pw)
Bram Moolenaar4287ed32018-02-17 20:35:29 +0100310 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100311 // use full width to end of the screen
Bram Moolenaar4287ed32018-02-17 20:35:29 +0100312 pum_col = Columns - max_width - pum_scrollbar;
313 if (pum_col < 0)
314 pum_col = 0;
315 }
Bram Moolenaara8f04aa2018-02-10 15:36:55 +0100316 }
317
318#ifdef FEAT_RIGHTLEFT
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +0100319 if (right_left)
Bram Moolenaar4287ed32018-02-17 20:35:29 +0100320 pum_width = pum_col - pum_scrollbar + 1;
Bram Moolenaara8f04aa2018-02-10 15:36:55 +0100321 else
322#endif
Bram Moolenaar4287ed32018-02-17 20:35:29 +0100323 pum_width = Columns - pum_col - pum_scrollbar;
Bram Moolenaara8f04aa2018-02-10 15:36:55 +0100324
Bram Moolenaar42443c72018-02-10 18:28:52 +0100325 if (pum_width < p_pw)
Bram Moolenaara8f04aa2018-02-10 15:36:55 +0100326 {
Bram Moolenaar42443c72018-02-10 18:28:52 +0100327 pum_width = p_pw;
Bram Moolenaara8f04aa2018-02-10 15:36:55 +0100328#ifdef FEAT_RIGHTLEFT
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +0100329 if (right_left)
Bram Moolenaara8f04aa2018-02-10 15:36:55 +0100330 {
331 if (pum_width > pum_col)
332 pum_width = pum_col;
333 }
334 else
335#endif
336 {
337 if (pum_width >= Columns - pum_col)
338 pum_width = Columns - pum_col - 1;
339 }
340 }
341 else if (pum_width > max_width + pum_kind_width
342 + pum_extra_width + 1
Bram Moolenaar42443c72018-02-10 18:28:52 +0100343 && pum_width > p_pw)
Bram Moolenaara8f04aa2018-02-10 15:36:55 +0100344 {
345 pum_width = max_width + pum_kind_width
346 + pum_extra_width + 1;
Bram Moolenaar42443c72018-02-10 18:28:52 +0100347 if (pum_width < p_pw)
348 pum_width = p_pw;
Bram Moolenaara8f04aa2018-02-10 15:36:55 +0100349 }
350 }
351
Bram Moolenaara5e66212017-09-29 22:42:33 +0200352 }
353 else if (Columns < def_width)
354 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100355 // not enough room, will use what we have
Bram Moolenaara5e66212017-09-29 22:42:33 +0200356#ifdef FEAT_RIGHTLEFT
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +0100357 if (right_left)
Bram Moolenaara5e66212017-09-29 22:42:33 +0200358 pum_col = Columns - 1;
359 else
360#endif
361 pum_col = 0;
362 pum_width = Columns - 1;
363 }
364 else
365 {
Bram Moolenaar42443c72018-02-10 18:28:52 +0100366 if (max_width > p_pw)
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100367 max_width = p_pw; // truncate
Bram Moolenaara5e66212017-09-29 22:42:33 +0200368#ifdef FEAT_RIGHTLEFT
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +0100369 if (right_left)
Bram Moolenaara5e66212017-09-29 22:42:33 +0200370 pum_col = max_width - 1;
371 else
372#endif
373 pum_col = Columns - max_width;
374 pum_width = max_width - pum_scrollbar;
375 }
376
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100377 // Set selected item and redraw. If the window size changed need to
378 // redo the positioning. Limit this to two times, when there is not
379 // much room the window size will keep changing.
Bram Moolenaara5e66212017-09-29 22:42:33 +0200380 } while (pum_set_selected(selected, redo_count) && ++redo_count <= 2);
Bram Moolenaar714cbe52020-11-16 19:12:00 +0100381
382 pum_redraw();
Bram Moolenaar4b779472005-10-04 09:12:31 +0000383}
384
385/*
Bram Moolenaarae654382019-01-17 21:09:05 +0100386 * Set a flag that when pum_redraw() is called it first calls update_screen().
387 * This will avoid clearing and redrawing the popup menu, prevent flicker.
388 */
389 void
Yegappan Lakshmanana23a11b2023-02-21 14:27:41 +0000390pum_call_update_screen(void)
Bram Moolenaarae654382019-01-17 21:09:05 +0100391{
392 call_update_screen = TRUE;
393
394 // Update the cursor position to be able to compute the popup menu
395 // position. The cursor line length may have changed because of the
396 // inserted completion.
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100397 curwin->w_valid &= ~(VALID_CROW|VALID_CHEIGHT);
Bram Moolenaarae654382019-01-17 21:09:05 +0100398 validate_cursor();
399}
400
401/*
402 * Return TRUE if we are going to redraw the popup menu and the screen position
403 * "row"/"col" is under the popup menu.
404 */
405 int
Bakudankun65555002021-11-17 20:40:16 +0000406pum_under_menu(int row, int col, int only_redrawing)
Bram Moolenaarae654382019-01-17 21:09:05 +0100407{
Bakudankun65555002021-11-17 20:40:16 +0000408 return (!only_redrawing || pum_will_redraw)
Bram Moolenaarae654382019-01-17 21:09:05 +0100409 && row >= pum_row
410 && row < pum_row + pum_height
411 && col >= pum_col - 1
Bram Moolenaare0c03c82021-04-23 21:01:34 +0200412 && col < pum_col + pum_width + pum_scrollbar;
Bram Moolenaarae654382019-01-17 21:09:05 +0100413}
414
415/*
Bram Moolenaar4b779472005-10-04 09:12:31 +0000416 * Redraw the popup menu, using "pum_first" and "pum_selected".
417 */
418 void
Bram Moolenaar05540972016-01-30 20:31:25 +0100419pum_redraw(void)
Bram Moolenaar4b779472005-10-04 09:12:31 +0000420{
421 int row = pum_row;
422 int col;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000423 int attr_scroll = highlight_attr[HLF_PSB];
424 int attr_thumb = highlight_attr[HLF_PST];
425 int attr;
Gianmaria Bajo6a7c7742023-03-10 16:35:53 +0000426 int *attrs; // array used for highlights
Bram Moolenaar4b779472005-10-04 09:12:31 +0000427 int i;
428 int idx;
429 char_u *s;
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +0000430 char_u *p = NULL;
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000431 int totwidth, width, w;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000432 int thumb_pos = 0;
Bram Moolenaarbdace832019-03-02 10:13:42 +0100433 int thumb_height = 1;
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000434 int round;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000435 int n;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000436
Bram Moolenaare638acc2023-03-15 17:08:51 +0000437 int attrsNorm[3];
438 int attrsSel[3];
439 // "word"
440 attrsNorm[0] = highlight_attr[HLF_PNI];
441 attrsSel[0] = highlight_attr[HLF_PSI];
442 // "kind"
443 attrsNorm[1] = highlight_attr[HLF_PNK];
444 attrsSel[1] = highlight_attr[HLF_PSK];
445 // "extra text"
446 attrsNorm[2] = highlight_attr[HLF_PNX];
447 attrsSel[2] = highlight_attr[HLF_PSX];
Gianmaria Bajo6a7c7742023-03-10 16:35:53 +0000448
Bram Moolenaarae654382019-01-17 21:09:05 +0100449 if (call_update_screen)
450 {
451 call_update_screen = FALSE;
Bram Moolenaar04357fb2019-12-10 21:50:56 +0100452 // Do not redraw in pum_may_redraw() and don't draw in the area where
453 // the popup menu will be.
454 pum_will_redraw = TRUE;
Bram Moolenaarae654382019-01-17 21:09:05 +0100455 update_screen(0);
Bram Moolenaar04357fb2019-12-10 21:50:56 +0100456 pum_will_redraw = FALSE;
Bram Moolenaarae654382019-01-17 21:09:05 +0100457 }
458
459 // never display more than we have
Bram Moolenaar4c1e6262013-11-06 04:04:33 +0100460 if (pum_first > pum_size - pum_height)
461 pum_first = pum_size - pum_height;
462
Bram Moolenaar4b779472005-10-04 09:12:31 +0000463 if (pum_scrollbar)
464 {
Bram Moolenaarbdace832019-03-02 10:13:42 +0100465 thumb_height = pum_height * pum_height / pum_size;
466 if (thumb_height == 0)
467 thumb_height = 1;
468 thumb_pos = (pum_first * (pum_height - thumb_height)
Bram Moolenaar4b779472005-10-04 09:12:31 +0000469 + (pum_size - pum_height) / 2)
470 / (pum_size - pum_height);
471 }
472
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100473#ifdef FEAT_PROP_POPUP
Bram Moolenaar33796b32019-06-08 16:01:13 +0200474 // The popup menu is drawn over popup menus with zindex under
475 // POPUPMENU_ZINDEX.
476 screen_zindex = POPUPMENU_ZINDEX;
477#endif
478
Bram Moolenaar4b779472005-10-04 09:12:31 +0000479 for (i = 0; i < pum_height; ++i)
480 {
481 idx = i + pum_first;
Gianmaria Bajo6a7c7742023-03-10 16:35:53 +0000482 attrs = (idx == pum_selected) ? attrsSel : attrsNorm;
483 attr = attrs[0]; // start with "word" highlight
Bram Moolenaar4b779472005-10-04 09:12:31 +0000484
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100485 // prepend a space if there is room
Bram Moolenaarabc97732007-08-08 20:49:37 +0000486#ifdef FEAT_RIGHTLEFT
487 if (curwin->w_p_rl)
488 {
Bram Moolenaar02631462017-09-22 15:20:32 +0200489 if (pum_col < curwin->w_wincol + curwin->w_width - 1)
Bram Moolenaarabc97732007-08-08 20:49:37 +0000490 screen_putchar(' ', row, pum_col + 1, attr);
491 }
492 else
493#endif
494 if (pum_col > 0)
495 screen_putchar(' ', row, pum_col - 1, attr);
Bram Moolenaar4b779472005-10-04 09:12:31 +0000496
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100497 // Display each entry, use two spaces for a Tab.
Gianmaria Bajo6a7c7742023-03-10 16:35:53 +0000498 // Do this 3 times:
499 // 0 - main text
500 // 1 - kind
501 // 2 - extra info
Bram Moolenaar4b779472005-10-04 09:12:31 +0000502 col = pum_col;
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000503 totwidth = 0;
Gianmaria Bajo6a7c7742023-03-10 16:35:53 +0000504 for (round = 0; round < 3; ++round)
Bram Moolenaar4b779472005-10-04 09:12:31 +0000505 {
Gianmaria Bajo6a7c7742023-03-10 16:35:53 +0000506 attr = attrs[round];
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000507 width = 0;
508 s = NULL;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000509 switch (round)
Bram Moolenaar4b779472005-10-04 09:12:31 +0000510 {
Gianmaria Bajo6a7c7742023-03-10 16:35:53 +0000511 case 0: p = pum_array[idx].pum_text; break;
512 case 1: p = pum_array[idx].pum_kind; break;
513 case 2: p = pum_array[idx].pum_extra; break;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000514 }
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000515 if (p != NULL)
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100516 for ( ; ; MB_PTR_ADV(p))
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000517 {
518 if (s == NULL)
519 s = p;
520 w = ptr2cells(p);
521 if (*p == NUL || *p == TAB || totwidth + w > pum_width)
522 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100523 // Display the text that fits or comes before a Tab.
524 // First convert it to printable characters.
Bram Moolenaarabc97732007-08-08 20:49:37 +0000525 char_u *st;
526 int saved = *p;
Bram Moolenaar7cc36e92007-03-27 10:42:05 +0000527
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +0100528 if (saved != NUL)
529 *p = NUL;
Bram Moolenaar7cc36e92007-03-27 10:42:05 +0000530 st = transstr(s);
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +0100531 if (saved != NUL)
532 *p = saved;
Bram Moolenaarabc97732007-08-08 20:49:37 +0000533#ifdef FEAT_RIGHTLEFT
534 if (curwin->w_p_rl)
Bram Moolenaar7cc36e92007-03-27 10:42:05 +0000535 {
Bram Moolenaarabc97732007-08-08 20:49:37 +0000536 if (st != NULL)
537 {
538 char_u *rt = reverse_text(st);
Bram Moolenaarabc97732007-08-08 20:49:37 +0000539
540 if (rt != NULL)
541 {
Bram Moolenaard836bb92010-01-19 18:06:03 +0100542 char_u *rt_start = rt;
543 int size;
544
545 size = vim_strsize(rt);
546 if (size > pum_width)
Bram Moolenaarabc97732007-08-08 20:49:37 +0000547 {
Bram Moolenaard836bb92010-01-19 18:06:03 +0100548 do
549 {
550 size -= has_mbyte
551 ? (*mb_ptr2cells)(rt) : 1;
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100552 MB_PTR_ADV(rt);
Bram Moolenaard836bb92010-01-19 18:06:03 +0100553 } while (size > pum_width);
554
555 if (size < pum_width)
556 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100557 // Most left character requires
558 // 2-cells but only 1 cell is
559 // available on screen. Put a
560 // '<' on the left of the pum
561 // item
Bram Moolenaard836bb92010-01-19 18:06:03 +0100562 *(--rt) = '<';
563 size++;
564 }
Bram Moolenaarabc97732007-08-08 20:49:37 +0000565 }
Bram Moolenaard836bb92010-01-19 18:06:03 +0100566 screen_puts_len(rt, (int)STRLEN(rt),
567 row, col - size + 1, attr);
568 vim_free(rt_start);
Bram Moolenaarabc97732007-08-08 20:49:37 +0000569 }
570 vim_free(st);
571 }
572 col -= width;
Bram Moolenaar7cc36e92007-03-27 10:42:05 +0000573 }
Bram Moolenaarabc97732007-08-08 20:49:37 +0000574 else
575#endif
576 {
577 if (st != NULL)
578 {
Bram Moolenaar714cbe52020-11-16 19:12:00 +0100579 int size = (int)STRLEN(st);
580 int cells = (*mb_string2cells)(st, size);
581
582 // only draw the text that fits
583 while (size > 0
584 && col + cells > pum_width + pum_col)
585 {
586 --size;
587 if (has_mbyte)
588 {
589 size -= (*mb_head_off)(st, st + size);
590 cells -= (*mb_ptr2cells)(st + size);
591 }
592 else
593 --cells;
594 }
595 screen_puts_len(st, size, row, col, attr);
Bram Moolenaarabc97732007-08-08 20:49:37 +0000596 vim_free(st);
597 }
598 col += width;
599 }
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000600
601 if (*p != TAB)
602 break;
603
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100604 // Display two spaces for a Tab.
Bram Moolenaarabc97732007-08-08 20:49:37 +0000605#ifdef FEAT_RIGHTLEFT
606 if (curwin->w_p_rl)
607 {
608 screen_puts_len((char_u *)" ", 2, row, col - 1,
609 attr);
610 col -= 2;
611 }
612 else
613#endif
614 {
615 screen_puts_len((char_u *)" ", 2, row, col, attr);
616 col += 2;
617 }
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000618 totwidth += 2;
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100619 s = NULL; // start text at next char
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000620 width = 0;
621 }
622 else
623 width += w;
624 }
625
Gianmaria Bajo6a7c7742023-03-10 16:35:53 +0000626 if (round > 0)
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000627 n = pum_kind_width + 1;
628 else
629 n = 1;
630
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100631 // Stop when there is nothing more to display.
Gianmaria Bajo6a7c7742023-03-10 16:35:53 +0000632 if (round == 2
633 || (round == 1 && pum_array[idx].pum_extra == NULL)
634 || (round == 0 && pum_array[idx].pum_kind == NULL
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000635 && pum_array[idx].pum_extra == NULL)
636 || pum_base_width + n >= pum_width)
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000637 break;
Bram Moolenaarabc97732007-08-08 20:49:37 +0000638#ifdef FEAT_RIGHTLEFT
639 if (curwin->w_p_rl)
640 {
641 screen_fill(row, row + 1, pum_col - pum_base_width - n + 1,
642 col + 1, ' ', ' ', attr);
643 col = pum_col - pum_base_width - n + 1;
644 }
645 else
646#endif
647 {
648 screen_fill(row, row + 1, col, pum_col + pum_base_width + n,
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000649 ' ', ' ', attr);
Bram Moolenaarabc97732007-08-08 20:49:37 +0000650 col = pum_col + pum_base_width + n;
651 }
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000652 totwidth = pum_base_width + n;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000653 }
654
Bram Moolenaarabc97732007-08-08 20:49:37 +0000655#ifdef FEAT_RIGHTLEFT
656 if (curwin->w_p_rl)
657 screen_fill(row, row + 1, pum_col - pum_width + 1, col + 1, ' ',
658 ' ', attr);
659 else
660#endif
661 screen_fill(row, row + 1, col, pum_col + pum_width, ' ', ' ',
662 attr);
Bram Moolenaar4b779472005-10-04 09:12:31 +0000663 if (pum_scrollbar > 0)
Bram Moolenaarabc97732007-08-08 20:49:37 +0000664 {
665#ifdef FEAT_RIGHTLEFT
666 if (curwin->w_p_rl)
667 screen_putchar(' ', row, pum_col - pum_width,
Bram Moolenaarbdace832019-03-02 10:13:42 +0100668 i >= thumb_pos && i < thumb_pos + thumb_height
Bram Moolenaar4b779472005-10-04 09:12:31 +0000669 ? attr_thumb : attr_scroll);
Bram Moolenaarabc97732007-08-08 20:49:37 +0000670 else
671#endif
672 screen_putchar(' ', row, pum_col + pum_width,
Bram Moolenaarbdace832019-03-02 10:13:42 +0100673 i >= thumb_pos && i < thumb_pos + thumb_height
Bram Moolenaarabc97732007-08-08 20:49:37 +0000674 ? attr_thumb : attr_scroll);
675 }
Bram Moolenaar4b779472005-10-04 09:12:31 +0000676
677 ++row;
678 }
Bram Moolenaar33796b32019-06-08 16:01:13 +0200679
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100680#ifdef FEAT_PROP_POPUP
Bram Moolenaar33796b32019-06-08 16:01:13 +0200681 screen_zindex = 0;
682#endif
Bram Moolenaar4b779472005-10-04 09:12:31 +0000683}
684
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100685#if (defined(FEAT_PROP_POPUP) && defined(FEAT_QUICKFIX)) || defined(PROTO)
Bram Moolenaardca7abe2019-10-20 18:17:57 +0200686/*
687 * Position the info popup relative to the popup menu item.
688 */
689 void
690pum_position_info_popup(win_T *wp)
Bram Moolenaarc1f87c92019-08-21 19:33:16 +0200691{
Bram Moolenaar202c3f72019-11-21 12:12:35 +0100692 int col = pum_col + pum_width + pum_scrollbar + 1;
Bram Moolenaarc1f87c92019-08-21 19:33:16 +0200693 int row = pum_row;
694 int botpos = POPPOS_BOTLEFT;
Bram Moolenaarde2396f2020-07-18 21:40:41 +0200695 int used_maxwidth_opt = FALSE;
Bram Moolenaarc1f87c92019-08-21 19:33:16 +0200696
Bram Moolenaardca7abe2019-10-20 18:17:57 +0200697 wp->w_popup_pos = POPPOS_TOPLEFT;
Bram Moolenaarc1f87c92019-08-21 19:33:16 +0200698 if (Columns - col < 20 && Columns - col < pum_col)
699 {
700 col = pum_col - 1;
Bram Moolenaardca7abe2019-10-20 18:17:57 +0200701 wp->w_popup_pos = POPPOS_TOPRIGHT;
Bram Moolenaarc1f87c92019-08-21 19:33:16 +0200702 botpos = POPPOS_BOTRIGHT;
Bram Moolenaardca7abe2019-10-20 18:17:57 +0200703 wp->w_maxwidth = pum_col - 1;
Bram Moolenaarc1f87c92019-08-21 19:33:16 +0200704 }
705 else
Bram Moolenaardca7abe2019-10-20 18:17:57 +0200706 wp->w_maxwidth = Columns - col + 1;
707 wp->w_maxwidth -= popup_extra_width(wp);
Bram Moolenaarde2396f2020-07-18 21:40:41 +0200708 if (wp->w_maxwidth_opt > 0 && wp->w_maxwidth > wp->w_maxwidth_opt)
709 {
710 // option value overrules computed value
711 wp->w_maxwidth = wp->w_maxwidth_opt;
712 used_maxwidth_opt = TRUE;
713 }
Bram Moolenaarc1f87c92019-08-21 19:33:16 +0200714
Bram Moolenaardca7abe2019-10-20 18:17:57 +0200715 row -= popup_top_extra(wp);
716 if (wp->w_popup_flags & POPF_INFO_MENU)
Bram Moolenaarc1f87c92019-08-21 19:33:16 +0200717 {
718 if (pum_row < pum_win_row)
719 {
720 // menu above cursor line, align with bottom
721 row += pum_height;
Bram Moolenaardca7abe2019-10-20 18:17:57 +0200722 wp->w_popup_pos = botpos;
Bram Moolenaarc1f87c92019-08-21 19:33:16 +0200723 }
724 else
725 // menu below cursor line, align with top
726 row += 1;
727 }
728 else
729 // align with the selected item
730 row += pum_selected - pum_first + 1;
731
Bram Moolenaarbef93ac2019-12-06 20:17:35 +0100732 wp->w_popup_flags &= ~POPF_HIDDEN;
Bram Moolenaarde2396f2020-07-18 21:40:41 +0200733 if (wp->w_maxwidth < 10 && !used_maxwidth_opt)
Bram Moolenaarbef93ac2019-12-06 20:17:35 +0100734 // The popup is not going to fit or will overlap with the cursor
735 // position, hide the popup.
736 wp->w_popup_flags |= POPF_HIDDEN;
737 else
738 popup_set_wantpos_rowcol(wp, row, col);
Bram Moolenaarc1f87c92019-08-21 19:33:16 +0200739}
740#endif
741
Bram Moolenaar4b779472005-10-04 09:12:31 +0000742/*
743 * Set the index of the currently selected item. The menu will scroll when
Bram Moolenaar1f35bf92006-03-07 22:38:47 +0000744 * necessary. When "n" is out of range don't scroll.
Bram Moolenaarfc1421e2006-04-20 22:17:20 +0000745 * This may be repeated when the preview window is used:
746 * "repeat" == 0: open preview window normally
747 * "repeat" == 1: open preview window but don't set the size
748 * "repeat" == 2: don't open preview window
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000749 * Returns TRUE when the window was resized and the location of the popup menu
750 * must be recomputed.
Bram Moolenaar4b779472005-10-04 09:12:31 +0000751 */
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000752 static int
Bram Moolenaar9cb698d2019-08-21 15:30:45 +0200753pum_set_selected(int n, int repeat UNUSED)
Bram Moolenaar4b779472005-10-04 09:12:31 +0000754{
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000755 int resized = FALSE;
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +0000756 int context = pum_height / 2;
Bram Moolenaareaf35242019-08-20 23:14:15 +0200757#ifdef FEAT_QUICKFIX
Bram Moolenaarf0bc15c2019-08-18 19:23:45 +0200758 int prev_selected = pum_selected;
Bram Moolenaareaf35242019-08-20 23:14:15 +0200759#endif
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100760#if defined(FEAT_PROP_POPUP) && defined(FEAT_QUICKFIX)
Bram Moolenaar576a4a62019-08-18 15:25:17 +0200761 int has_info = FALSE;
762#endif
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000763
Bram Moolenaar4b779472005-10-04 09:12:31 +0000764 pum_selected = n;
765
Bram Moolenaar1f35bf92006-03-07 22:38:47 +0000766 if (pum_selected >= 0 && pum_selected < pum_size)
Bram Moolenaar4b779472005-10-04 09:12:31 +0000767 {
Bram Moolenaare3226be2005-12-18 22:10:00 +0000768 if (pum_first > pum_selected - 4)
769 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100770 // scroll down; when we did a jump it's probably a PageUp then
771 // scroll a whole page
Bram Moolenaare3226be2005-12-18 22:10:00 +0000772 if (pum_first > pum_selected - 2)
773 {
Bram Moolenaar7df351e2006-01-23 22:30:28 +0000774 pum_first -= pum_height - 2;
Bram Moolenaare3226be2005-12-18 22:10:00 +0000775 if (pum_first < 0)
776 pum_first = 0;
Bram Moolenaar7df351e2006-01-23 22:30:28 +0000777 else if (pum_first > pum_selected)
778 pum_first = pum_selected;
Bram Moolenaare3226be2005-12-18 22:10:00 +0000779 }
780 else
781 pum_first = pum_selected;
782 }
783 else if (pum_first < pum_selected - pum_height + 5)
784 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100785 // scroll up; when we did a jump it's probably a PageDown then
786 // scroll a whole page
Bram Moolenaare3226be2005-12-18 22:10:00 +0000787 if (pum_first < pum_selected - pum_height + 1 + 2)
Bram Moolenaar7df351e2006-01-23 22:30:28 +0000788 {
789 pum_first += pum_height - 2;
790 if (pum_first < pum_selected - pum_height + 1)
791 pum_first = pum_selected - pum_height + 1;
792 }
Bram Moolenaare3226be2005-12-18 22:10:00 +0000793 else
794 pum_first = pum_selected - pum_height + 1;
795 }
Bram Moolenaar4b779472005-10-04 09:12:31 +0000796
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100797 // Give a few lines of context when possible.
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +0000798 if (context > 3)
799 context = 3;
800 if (pum_height > 2)
Bram Moolenaar4b779472005-10-04 09:12:31 +0000801 {
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +0000802 if (pum_first > pum_selected - context)
Bram Moolenaar4b779472005-10-04 09:12:31 +0000803 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100804 // scroll down
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +0000805 pum_first = pum_selected - context;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000806 if (pum_first < 0)
807 pum_first = 0;
808 }
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +0000809 else if (pum_first < pum_selected + context - pum_height + 1)
Bram Moolenaar4b779472005-10-04 09:12:31 +0000810 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100811 // scroll up
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +0000812 pum_first = pum_selected + context - pum_height + 1;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000813 }
814 }
Bram Moolenaar576a4a62019-08-18 15:25:17 +0200815 // adjust for the number of lines displayed
816 if (pum_first > pum_size - pum_height)
817 pum_first = pum_size - pum_height;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000818
Bram Moolenaar4033c552017-09-16 20:54:51 +0200819#if defined(FEAT_QUICKFIX)
Bram Moolenaard2cec5b2006-03-28 21:08:56 +0000820 /*
821 * Show extra info in the preview window if there is something and
Bram Moolenaar202c3f72019-11-21 12:12:35 +0100822 * 'completeopt' contains "preview" or "popup" or "popuphidden".
Bram Moolenaarfc1421e2006-04-20 22:17:20 +0000823 * Skip this when tried twice already.
824 * Skip this also when there is not much room.
Bram Moolenaard2cec5b2006-03-28 21:08:56 +0000825 * NOTE: Be very careful not to sync undo!
826 */
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000827 if (pum_array[pum_selected].pum_info != NULL
Bram Moolenaarfc1421e2006-04-20 22:17:20 +0000828 && Rows > 10
829 && repeat <= 1
830 && vim_strchr(p_cot, 'p') != NULL)
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000831 {
832 win_T *curwin_save = curwin;
Bram Moolenaar9ad89c62017-10-26 22:04:04 +0200833 tabpage_T *curtab_save = curtab;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000834 int res = OK;
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100835# ifdef FEAT_PROP_POPUP
Bram Moolenaardca7abe2019-10-20 18:17:57 +0200836 use_popup_T use_popup;
Bram Moolenaar576a4a62019-08-18 15:25:17 +0200837# else
Bram Moolenaara2c2ae42019-11-30 20:58:46 +0100838# define use_popup USEPOPUP_NONE
Bram Moolenaar576a4a62019-08-18 15:25:17 +0200839# endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100840# ifdef FEAT_PROP_POPUP
Bram Moolenaar576a4a62019-08-18 15:25:17 +0200841 has_info = TRUE;
Bram Moolenaardca7abe2019-10-20 18:17:57 +0200842 if (strstr((char *)p_cot, "popuphidden") != NULL)
843 use_popup = USEPOPUP_HIDDEN;
844 else if (strstr((char *)p_cot, "popup") != NULL)
845 use_popup = USEPOPUP_NORMAL;
846 else
847 use_popup = USEPOPUP_NONE;
Bram Moolenaar2dfae042020-11-15 14:09:37 +0100848 if (use_popup != USEPOPUP_NONE)
849 // don't use WinEnter or WinLeave autocommands for the info
850 // popup
851 block_autocmds();
Bram Moolenaard570ab92019-09-03 23:20:05 +0200852# endif
Bram Moolenaardca7abe2019-10-20 18:17:57 +0200853 // Open a preview window and set "curwin" to it.
854 // 3 lines by default, prefer 'previewheight' if set and smaller.
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000855 g_do_tagpreview = 3;
Bram Moolenaaree236d02010-10-27 17:11:15 +0200856 if (p_pvh > 0 && p_pvh < g_do_tagpreview)
857 g_do_tagpreview = p_pvh;
Bram Moolenaarc8045152014-07-09 19:58:24 +0200858 ++RedrawingDisabled;
Bram Moolenaar576a4a62019-08-18 15:25:17 +0200859 // Prevent undo sync here, if an autocommand syncs undo weird
860 // things can happen to the undo tree.
Bram Moolenaare7d13762015-10-30 14:23:33 +0100861 ++no_u_sync;
Bram Moolenaar576a4a62019-08-18 15:25:17 +0200862 resized = prepare_tagpreview(FALSE, FALSE, use_popup);
Bram Moolenaare7d13762015-10-30 14:23:33 +0100863 --no_u_sync;
Bram Moolenaarc8045152014-07-09 19:58:24 +0200864 --RedrawingDisabled;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000865 g_do_tagpreview = 0;
866
Bram Moolenaar576a4a62019-08-18 15:25:17 +0200867 if (curwin->w_p_pvw
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100868# ifdef FEAT_PROP_POPUP
Bram Moolenaar576a4a62019-08-18 15:25:17 +0200869 || (curwin->w_popup_flags & POPF_INFO)
870# endif
871 )
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000872 {
Bram Moolenaar50e53762016-10-27 14:49:15 +0200873 if (!resized
874 && curbuf->b_nwindows == 1
875 && curbuf->b_fname == NULL
Bram Moolenaar26910de2019-06-15 19:37:15 +0200876 && bt_nofile(curbuf)
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000877 && curbuf->b_p_bh[0] == 'w')
878 {
Bram Moolenaar576a4a62019-08-18 15:25:17 +0200879 // Already a "wipeout" buffer, make it empty.
Bram Moolenaarb5aedf32017-03-12 18:23:53 +0100880 while (!BUFEMPTY())
Bram Moolenaarca70c072020-05-30 20:30:46 +0200881 ml_delete((linenr_T)1);
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000882 }
Bram Moolenaar779b74b2006-04-10 14:55:34 +0000883 else
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000884 {
Bram Moolenaar576a4a62019-08-18 15:25:17 +0200885 // Don't want to sync undo in the current buffer.
Bram Moolenaar779b74b2006-04-10 14:55:34 +0000886 ++no_u_sync;
Bram Moolenaar701f7af2008-11-15 13:12:07 +0000887 res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0, NULL);
Bram Moolenaar779b74b2006-04-10 14:55:34 +0000888 --no_u_sync;
889 if (res == OK)
890 {
Bram Moolenaar576a4a62019-08-18 15:25:17 +0200891 // Edit a new, empty buffer. Set options for a "wipeout"
892 // buffer.
Bram Moolenaar31e5c602022-04-15 13:53:33 +0100893 set_option_value_give_err((char_u *)"swf",
894 0L, NULL, OPT_LOCAL);
895 set_option_value_give_err((char_u *)"bl",
896 0L, NULL, OPT_LOCAL);
897 set_option_value_give_err((char_u *)"bt",
898 0L, (char_u *)"nofile", OPT_LOCAL);
899 set_option_value_give_err((char_u *)"bh",
900 0L, (char_u *)"wipe", OPT_LOCAL);
901 set_option_value_give_err((char_u *)"diff",
902 0L, NULL, OPT_LOCAL);
Bram Moolenaar779b74b2006-04-10 14:55:34 +0000903 }
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000904 }
905 if (res == OK)
906 {
907 char_u *p, *e;
908 linenr_T lnum = 0;
909
910 for (p = pum_array[pum_selected].pum_info; *p != NUL; )
911 {
912 e = vim_strchr(p, '\n');
913 if (e == NULL)
914 {
915 ml_append(lnum++, p, 0, FALSE);
916 break;
917 }
918 else
919 {
920 *e = NUL;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +0000921 ml_append(lnum++, p, (int)(e - p + 1), FALSE);
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000922 *e = '\n';
923 p = e + 1;
924 }
925 }
Bram Moolenaar576a4a62019-08-18 15:25:17 +0200926 // delete the empty last line
Bram Moolenaarca70c072020-05-30 20:30:46 +0200927 ml_delete(curbuf->b_ml.ml_line_count);
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000928
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100929 // Increase the height of the preview window to show the
930 // text, but no more than 'previewheight' lines.
Bram Moolenaardca7abe2019-10-20 18:17:57 +0200931 if (repeat == 0 && use_popup == USEPOPUP_NONE)
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000932 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +0000933 if (lnum > p_pvh)
934 lnum = p_pvh;
935 if (curwin->w_height < lnum)
936 {
937 win_setheight((int)lnum);
938 resized = TRUE;
939 }
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000940 }
941
942 curbuf->b_changed = 0;
943 curbuf->b_p_ma = FALSE;
Bram Moolenaarf0bc15c2019-08-18 19:23:45 +0200944 if (pum_selected != prev_selected)
945 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100946# ifdef FEAT_PROP_POPUP
Bram Moolenaarf0bc15c2019-08-18 19:23:45 +0200947 curwin->w_firstline = 1;
948# endif
949 curwin->w_topline = 1;
950 }
951 else if (curwin->w_topline > curbuf->b_ml.ml_line_count)
952 curwin->w_topline = curbuf->b_ml.ml_line_count;
953 curwin->w_cursor.lnum = curwin->w_topline;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000954 curwin->w_cursor.col = 0;
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100955# ifdef FEAT_PROP_POPUP
Bram Moolenaardca7abe2019-10-20 18:17:57 +0200956 if (use_popup != USEPOPUP_NONE)
Bram Moolenaarc1f87c92019-08-21 19:33:16 +0200957 {
Bram Moolenaardca7abe2019-10-20 18:17:57 +0200958 pum_position_info_popup(curwin);
Bram Moolenaarc1f87c92019-08-21 19:33:16 +0200959 if (win_valid(curwin_save))
Bram Moolenaara4d158b2022-08-14 14:17:45 +0100960 redraw_win_later(curwin_save, UPD_SOME_VALID);
Bram Moolenaarc1f87c92019-08-21 19:33:16 +0200961 }
962# endif
Bram Moolenaar9ad89c62017-10-26 22:04:04 +0200963 if ((curwin != curwin_save && win_valid(curwin_save))
964 || (curtab != curtab_save
965 && valid_tabpage(curtab_save)))
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000966 {
Bram Moolenaarb80d2fb2021-04-27 20:06:57 +0200967 int save_redr_status;
968
Bram Moolenaar9ad89c62017-10-26 22:04:04 +0200969 if (curtab != curtab_save && valid_tabpage(curtab_save))
970 goto_tabpage_tp(curtab_save, FALSE, FALSE);
971
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100972 // When the first completion is done and the preview
973 // window is not resized, skip the preview window's
974 // status line redrawing.
Bram Moolenaar2bace3e2014-07-23 21:10:43 +0200975 if (ins_compl_active() && !resized)
976 curwin->w_redr_status = FALSE;
977
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100978 // Return cursor to where we were
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000979 validate_cursor();
Bram Moolenaara4d158b2022-08-14 14:17:45 +0100980 redraw_later(UPD_SOME_VALID);
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000981
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100982 // When the preview window was resized we need to
983 // update the view on the buffer. Only go back to
984 // the window when needed, otherwise it will always be
Bram Moolenaar5e5a98d2019-12-15 14:55:33 +0100985 // redrawn.
Bram Moolenaar5dd143e2019-08-15 21:34:34 +0200986 if (resized && win_valid(curwin_save))
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000987 {
Bram Moolenaare7d13762015-10-30 14:23:33 +0100988 ++no_u_sync;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000989 win_enter(curwin_save, TRUE);
Bram Moolenaare7d13762015-10-30 14:23:33 +0100990 --no_u_sync;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000991 update_topline();
992 }
993
Bram Moolenaar63d9e732019-12-05 21:10:38 +0100994 // Update the screen before drawing the popup menu.
995 // Enable updating the status lines.
Bram Moolenaar04357fb2019-12-10 21:50:56 +0100996 pum_pretend_not_visible = TRUE;
Bram Moolenaarb80d2fb2021-04-27 20:06:57 +0200997
Bram Moolenaar04357fb2019-12-10 21:50:56 +0100998 // But don't draw text at the new popup menu position,
Bram Moolenaar5e5a98d2019-12-15 14:55:33 +0100999 // it causes flicker. When resizing we need to draw
1000 // anyway, the position may change later.
Bram Moolenaarb80d2fb2021-04-27 20:06:57 +02001001 // Also do not redraw the status line of the original
1002 // current window here, to avoid it gets drawn with
1003 // StatusLineNC for a moment and cause flicker.
Bram Moolenaar5e5a98d2019-12-15 14:55:33 +01001004 pum_will_redraw = !resized;
Bram Moolenaarb80d2fb2021-04-27 20:06:57 +02001005 save_redr_status = curwin_save->w_redr_status;
1006 curwin_save->w_redr_status = FALSE;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +00001007 update_screen(0);
Bram Moolenaar04357fb2019-12-10 21:50:56 +01001008 pum_pretend_not_visible = FALSE;
1009 pum_will_redraw = FALSE;
Bram Moolenaarb80d2fb2021-04-27 20:06:57 +02001010 curwin_save->w_redr_status = save_redr_status;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +00001011
Bram Moolenaard2cec5b2006-03-28 21:08:56 +00001012 if (!resized && win_valid(curwin_save))
Bram Moolenaare7d13762015-10-30 14:23:33 +01001013 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001014# ifdef FEAT_PROP_POPUP
Bram Moolenaardca7abe2019-10-20 18:17:57 +02001015 win_T *wp = curwin;
1016# endif
Bram Moolenaare7d13762015-10-30 14:23:33 +01001017 ++no_u_sync;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +00001018 win_enter(curwin_save, TRUE);
Bram Moolenaare7d13762015-10-30 14:23:33 +01001019 --no_u_sync;
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001020# ifdef FEAT_PROP_POPUP
Bram Moolenaardca7abe2019-10-20 18:17:57 +02001021 if (use_popup == USEPOPUP_HIDDEN && win_valid(wp))
1022 popup_hide(wp);
1023# endif
Bram Moolenaare7d13762015-10-30 14:23:33 +01001024 }
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +00001025
Bram Moolenaar63d9e732019-12-05 21:10:38 +01001026 // May need to update the screen again when there are
1027 // autocommands involved.
Bram Moolenaar04357fb2019-12-10 21:50:56 +01001028 pum_pretend_not_visible = TRUE;
Bram Moolenaar5e5a98d2019-12-15 14:55:33 +01001029 pum_will_redraw = !resized;
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +00001030 update_screen(0);
Bram Moolenaar04357fb2019-12-10 21:50:56 +01001031 pum_pretend_not_visible = FALSE;
1032 pum_will_redraw = FALSE;
Bram Moolenaarae654382019-01-17 21:09:05 +01001033 call_update_screen = FALSE;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +00001034 }
1035 }
1036 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001037# if defined(FEAT_PROP_POPUP) && defined(FEAT_QUICKFIX)
Bram Moolenaar5dd143e2019-08-15 21:34:34 +02001038 if (WIN_IS_POPUP(curwin))
1039 // can't keep focus in a popup window
1040 win_enter(firstwin, TRUE);
1041# endif
Bram Moolenaar2dfae042020-11-15 14:09:37 +01001042# ifdef FEAT_PROP_POPUP
1043 if (use_popup != USEPOPUP_NONE)
1044 unblock_autocmds();
1045# endif
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +00001046 }
1047#endif
Bram Moolenaar4b779472005-10-04 09:12:31 +00001048 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001049#if defined(FEAT_PROP_POPUP) && defined(FEAT_QUICKFIX)
Bram Moolenaar576a4a62019-08-18 15:25:17 +02001050 if (!has_info)
Bram Moolenaarc7c5f102019-08-21 18:31:03 +02001051 // hide any popup info window
1052 popup_hide_info();
Bram Moolenaare2c453d2019-08-21 14:37:09 +02001053#endif
Bram Moolenaar4b779472005-10-04 09:12:31 +00001054
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +00001055 return resized;
Bram Moolenaar4b779472005-10-04 09:12:31 +00001056}
1057
1058/*
1059 * Undisplay the popup menu (later).
1060 */
1061 void
Bram Moolenaar05540972016-01-30 20:31:25 +01001062pum_undisplay(void)
Bram Moolenaar4b779472005-10-04 09:12:31 +00001063{
1064 pum_array = NULL;
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001065 redraw_all_later(UPD_NOT_VALID);
Bram Moolenaar2d694602006-08-22 19:48:48 +00001066 redraw_tabline = TRUE;
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +00001067 status_redraw_all();
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001068#if defined(FEAT_PROP_POPUP) && defined(FEAT_QUICKFIX)
Bram Moolenaarc7c5f102019-08-21 18:31:03 +02001069 // hide any popup info window
1070 popup_hide_info();
Bram Moolenaar576a4a62019-08-18 15:25:17 +02001071#endif
Bram Moolenaar4b779472005-10-04 09:12:31 +00001072}
1073
1074/*
1075 * Clear the popup menu. Currently only resets the offset to the first
1076 * displayed item.
1077 */
1078 void
Bram Moolenaar05540972016-01-30 20:31:25 +01001079pum_clear(void)
Bram Moolenaar4b779472005-10-04 09:12:31 +00001080{
1081 pum_first = 0;
1082}
1083
1084/*
Bram Moolenaar04357fb2019-12-10 21:50:56 +01001085 * Return TRUE if the popup menu is displayed. Used to avoid some redrawing
1086 * that could overwrite it. Overruled when "pum_pretend_not_visible" is set,
1087 * used to redraw the status lines.
Bram Moolenaar4b779472005-10-04 09:12:31 +00001088 */
1089 int
Bram Moolenaar05540972016-01-30 20:31:25 +01001090pum_visible(void)
Bram Moolenaar4b779472005-10-04 09:12:31 +00001091{
Bram Moolenaar04357fb2019-12-10 21:50:56 +01001092 return !pum_pretend_not_visible && pum_array != NULL;
Bram Moolenaar4b779472005-10-04 09:12:31 +00001093}
1094
Bram Moolenaare3226be2005-12-18 22:10:00 +00001095/*
Bram Moolenaare0c03c82021-04-23 21:01:34 +02001096 * Return TRUE if the popup can be redrawn in the same position.
1097 */
1098 static int
1099pum_in_same_position(void)
1100{
1101 return pum_window != curwin
1102 || (pum_win_row == curwin->w_wrow + W_WINROW(curwin)
1103 && pum_win_height == curwin->w_height
1104 && pum_win_col == curwin->w_wincol
1105 && pum_win_width == curwin->w_width);
1106}
1107
1108/*
1109 * Return TRUE when pum_may_redraw() will call pum_redraw().
1110 * This means that the pum area should not be overwritten to avoid flicker.
1111 */
1112 int
1113pum_redraw_in_same_position(void)
1114{
1115 if (!pum_visible() || pum_will_redraw)
1116 return FALSE; // nothing to do
1117
1118 return pum_in_same_position();
1119}
1120
1121/*
Bram Moolenaar491ac282018-06-17 14:47:55 +02001122 * Reposition the popup menu to adjust for window layout changes.
1123 */
1124 void
1125pum_may_redraw(void)
1126{
1127 pumitem_T *array = pum_array;
1128 int len = pum_size;
1129 int selected = pum_selected;
1130
Bram Moolenaar04357fb2019-12-10 21:50:56 +01001131 if (!pum_visible() || pum_will_redraw)
Bram Moolenaar491ac282018-06-17 14:47:55 +02001132 return; // nothing to do
1133
Bram Moolenaare0c03c82021-04-23 21:01:34 +02001134 if (pum_in_same_position())
Bram Moolenaar491ac282018-06-17 14:47:55 +02001135 {
1136 // window position didn't change, redraw in the same position
1137 pum_redraw();
1138 }
1139 else
1140 {
1141 int wcol = curwin->w_wcol;
1142
1143 // Window layout changed, recompute the position.
1144 // Use the remembered w_wcol value, the cursor may have moved when a
1145 // completion was inserted, but we want the menu in the same position.
1146 pum_undisplay();
1147 curwin->w_wcol = pum_win_wcol;
1148 curwin->w_valid |= VALID_WCOL;
1149 pum_display(array, len, selected);
1150 curwin->w_wcol = wcol;
1151 }
1152}
1153
1154/*
Bram Moolenaare3226be2005-12-18 22:10:00 +00001155 * Return the height of the popup menu, the number of entries visible.
1156 * Only valid when pum_visible() returns TRUE!
1157 */
1158 int
Bram Moolenaar05540972016-01-30 20:31:25 +01001159pum_get_height(void)
Bram Moolenaare3226be2005-12-18 22:10:00 +00001160{
1161 return pum_height;
1162}
1163
Bram Moolenaar9cb698d2019-08-21 15:30:45 +02001164#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaard7f246c2019-04-08 18:15:41 +02001165/*
1166 * Add size information about the pum to "dict".
1167 */
1168 void
1169pum_set_event_info(dict_T *dict)
1170{
1171 if (!pum_visible())
1172 return;
Bram Moolenaarc0300632020-03-16 20:07:16 +01001173 (void)dict_add_number(dict, "height", pum_height);
1174 (void)dict_add_number(dict, "width", pum_width);
1175 (void)dict_add_number(dict, "row", pum_row);
1176 (void)dict_add_number(dict, "col", pum_col);
1177 (void)dict_add_number(dict, "size", pum_size);
1178 (void)dict_add_bool(dict, "scrollbar",
1179 pum_scrollbar ? VVAL_TRUE : VVAL_FALSE);
Bram Moolenaard7f246c2019-04-08 18:15:41 +02001180}
Bram Moolenaar9cb698d2019-08-21 15:30:45 +02001181#endif
Bram Moolenaard7f246c2019-04-08 18:15:41 +02001182
Bram Moolenaare2c453d2019-08-21 14:37:09 +02001183#if defined(FEAT_BEVAL_TERM) || defined(FEAT_TERM_POPUP_MENU) || defined(PROTO)
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001184 static void
1185pum_position_at_mouse(int min_width)
1186{
1187 if (Rows - mouse_row > pum_size)
1188 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +01001189 // Enough space below the mouse row.
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001190 pum_row = mouse_row + 1;
1191 if (pum_height > Rows - pum_row)
1192 pum_height = Rows - pum_row;
1193 }
1194 else
1195 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +01001196 // Show above the mouse row, reduce height if it does not fit.
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001197 pum_row = mouse_row - pum_size;
1198 if (pum_row < 0)
1199 {
1200 pum_height += pum_row;
1201 pum_row = 0;
1202 }
1203 }
1204 if (Columns - mouse_col >= pum_base_width
1205 || Columns - mouse_col > min_width)
Bram Moolenaar63d9e732019-12-05 21:10:38 +01001206 // Enough space to show at mouse column.
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001207 pum_col = mouse_col;
1208 else
Bram Moolenaar63d9e732019-12-05 21:10:38 +01001209 // Not enough space, right align with window.
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001210 pum_col = Columns - (pum_base_width > min_width
1211 ? min_width : pum_base_width);
1212
1213 pum_width = Columns - pum_col;
1214 if (pum_width > pum_base_width + 1)
1215 pum_width = pum_base_width + 1;
Bram Moolenaar0e6e1792018-06-17 17:10:59 +02001216
1217 // Do not redraw at cursor position.
1218 pum_window = NULL;
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001219}
1220
Bram Moolenaare2c453d2019-08-21 14:37:09 +02001221#endif
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001222
Bram Moolenaare2c453d2019-08-21 14:37:09 +02001223#if defined(FEAT_BEVAL_TERM) || defined(PROTO)
Bram Moolenaar51b0f372017-11-18 18:52:04 +01001224static pumitem_T *balloon_array = NULL;
1225static int balloon_arraysize;
Bram Moolenaar51b0f372017-11-18 18:52:04 +01001226
Bram Moolenaare2c453d2019-08-21 14:37:09 +02001227# define BALLOON_MIN_WIDTH 50
1228# define BALLOON_MIN_HEIGHT 10
Bram Moolenaar51b0f372017-11-18 18:52:04 +01001229
Bram Moolenaar246fe032017-11-19 19:56:27 +01001230typedef struct {
1231 char_u *start;
1232 int bytelen;
1233 int cells;
1234 int indent;
1235} balpart_T;
1236
1237/*
1238 * Split a string into parts to display in the balloon.
1239 * Aimed at output from gdb. Attempts to split at white space, preserve quoted
1240 * strings and make a struct look good.
1241 * Resulting array is stored in "array" and returns the size of the array.
1242 */
1243 int
1244split_message(char_u *mesg, pumitem_T **array)
1245{
1246 garray_T ga;
1247 char_u *p;
1248 balpart_T *item;
1249 int quoted = FALSE;
1250 int height;
1251 int line;
1252 int item_idx;
1253 int indent = 0;
1254 int max_cells = 0;
Bram Moolenaard1c1c822019-11-09 16:59:14 +01001255 int max_height = Rows / 2 - 1;
Bram Moolenaar246fe032017-11-19 19:56:27 +01001256 int long_item_count = 0;
1257 int split_long_items = FALSE;
1258
1259 ga_init2(&ga, sizeof(balpart_T), 20);
1260 p = mesg;
1261
1262 while (*p != NUL)
1263 {
1264 if (ga_grow(&ga, 1) == FAIL)
1265 goto failed;
1266 item = ((balpart_T *)ga.ga_data) + ga.ga_len;
1267 item->start = p;
1268 item->indent = indent;
1269 item->cells = indent * 2;
1270 ++ga.ga_len;
1271 while (*p != NUL)
1272 {
1273 if (*p == '"')
1274 quoted = !quoted;
Bram Moolenaard1c1c822019-11-09 16:59:14 +01001275 else if (*p == '\n')
1276 break;
Bram Moolenaar246fe032017-11-19 19:56:27 +01001277 else if (*p == '\\' && p[1] != NUL)
1278 ++p;
1279 else if (!quoted)
1280 {
1281 if ((*p == ',' && p[1] == ' ') || *p == '{' || *p == '}')
1282 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +01001283 // Looks like a good point to break.
Bram Moolenaar246fe032017-11-19 19:56:27 +01001284 if (*p == '{')
1285 ++indent;
1286 else if (*p == '}' && indent > 0)
1287 --indent;
1288 ++item->cells;
1289 p = skipwhite(p + 1);
1290 break;
1291 }
1292 }
1293 item->cells += ptr2cells(p);
Bram Moolenaar1614a142019-10-06 22:00:13 +02001294 p += mb_ptr2len(p);
Bram Moolenaar246fe032017-11-19 19:56:27 +01001295 }
1296 item->bytelen = p - item->start;
Bram Moolenaard1c1c822019-11-09 16:59:14 +01001297 if (*p == '\n')
1298 ++p;
Bram Moolenaar246fe032017-11-19 19:56:27 +01001299 if (item->cells > max_cells)
1300 max_cells = item->cells;
Bram Moolenaara3571eb2017-11-26 16:53:16 +01001301 long_item_count += (item->cells - 1) / BALLOON_MIN_WIDTH;
Bram Moolenaar246fe032017-11-19 19:56:27 +01001302 }
1303
1304 height = 2 + ga.ga_len;
1305
Bram Moolenaar63d9e732019-12-05 21:10:38 +01001306 // If there are long items and the height is below the limit: split lines
Bram Moolenaar246fe032017-11-19 19:56:27 +01001307 if (long_item_count > 0 && height + long_item_count <= max_height)
1308 {
1309 split_long_items = TRUE;
1310 height += long_item_count;
1311 }
1312
Bram Moolenaar63d9e732019-12-05 21:10:38 +01001313 // Limit to half the window height, it has to fit above or below the mouse
1314 // position.
Bram Moolenaar246fe032017-11-19 19:56:27 +01001315 if (height > max_height)
1316 height = max_height;
Bram Moolenaarc799fe22019-05-28 23:08:19 +02001317 *array = ALLOC_CLEAR_MULT(pumitem_T, height);
Bram Moolenaar246fe032017-11-19 19:56:27 +01001318 if (*array == NULL)
1319 goto failed;
1320
Bram Moolenaar63d9e732019-12-05 21:10:38 +01001321 // Add an empty line above and below, looks better.
Bram Moolenaar246fe032017-11-19 19:56:27 +01001322 (*array)->pum_text = vim_strsave((char_u *)"");
1323 (*array + height - 1)->pum_text = vim_strsave((char_u *)"");
1324
1325 for (line = 1, item_idx = 0; line < height - 1; ++item_idx)
1326 {
1327 int skip;
1328 int thislen;
1329 int copylen;
1330 int ind;
1331 int cells;
1332
1333 item = ((balpart_T *)ga.ga_data) + item_idx;
Bram Moolenaar9ae862e2019-11-21 13:27:06 +01001334 if (item->bytelen == 0)
1335 (*array)[line++].pum_text = vim_strsave((char_u *)"");
1336 else
1337 for (skip = 0; skip < item->bytelen; skip += thislen)
Bram Moolenaar246fe032017-11-19 19:56:27 +01001338 {
Bram Moolenaar9ae862e2019-11-21 13:27:06 +01001339 if (split_long_items && item->cells >= BALLOON_MIN_WIDTH)
1340 {
1341 cells = item->indent * 2;
1342 for (p = item->start + skip;
1343 p < item->start + item->bytelen;
Bram Moolenaar1614a142019-10-06 22:00:13 +02001344 p += mb_ptr2len(p))
Bram Moolenaar9ae862e2019-11-21 13:27:06 +01001345 if ((cells += ptr2cells(p)) > BALLOON_MIN_WIDTH)
1346 break;
1347 thislen = p - (item->start + skip);
1348 }
1349 else
1350 thislen = item->bytelen;
1351
1352 // put indent at the start
1353 p = alloc(thislen + item->indent * 2 + 1);
1354 if (p == NULL)
1355 {
1356 for (line = 0; line <= height - 1; ++line)
1357 vim_free((*array)[line].pum_text);
1358 vim_free(*array);
1359 goto failed;
1360 }
1361 for (ind = 0; ind < item->indent * 2; ++ind)
1362 p[ind] = ' ';
1363
1364 // exclude spaces at the end of the string
1365 for (copylen = thislen; copylen > 0; --copylen)
1366 if (item->start[skip + copylen - 1] != ' ')
Bram Moolenaar246fe032017-11-19 19:56:27 +01001367 break;
Bram Moolenaar9ae862e2019-11-21 13:27:06 +01001368
1369 vim_strncpy(p + ind, item->start + skip, copylen);
1370 (*array)[line].pum_text = p;
Bram Moolenaar63d9e732019-12-05 21:10:38 +01001371 item->indent = 0; // wrapped line has no indent
Bram Moolenaar9ae862e2019-11-21 13:27:06 +01001372 ++line;
Bram Moolenaar246fe032017-11-19 19:56:27 +01001373 }
Bram Moolenaar246fe032017-11-19 19:56:27 +01001374 }
1375 ga_clear(&ga);
1376 return height;
1377
1378failed:
1379 ga_clear(&ga);
1380 return 0;
1381}
1382
Bram Moolenaar51b0f372017-11-18 18:52:04 +01001383 void
1384ui_remove_balloon(void)
1385{
Yegappan Lakshmananf97a2952023-01-18 18:17:48 +00001386 if (balloon_array == NULL)
1387 return;
1388
1389 pum_undisplay();
1390 while (balloon_arraysize > 0)
1391 vim_free(balloon_array[--balloon_arraysize].pum_text);
1392 VIM_CLEAR(balloon_array);
Bram Moolenaar51b0f372017-11-18 18:52:04 +01001393}
1394
1395/*
1396 * Terminal version of a balloon, uses the popup menu code.
1397 */
1398 void
Bram Moolenaar246fe032017-11-19 19:56:27 +01001399ui_post_balloon(char_u *mesg, list_T *list)
Bram Moolenaar51b0f372017-11-18 18:52:04 +01001400{
1401 ui_remove_balloon();
1402
Bram Moolenaar246fe032017-11-19 19:56:27 +01001403 if (mesg == NULL && list == NULL)
Bram Moolenaarbe0a2592019-05-09 13:50:16 +02001404 {
1405 pum_undisplay();
Bram Moolenaar246fe032017-11-19 19:56:27 +01001406 return;
Bram Moolenaarbe0a2592019-05-09 13:50:16 +02001407 }
Bram Moolenaar246fe032017-11-19 19:56:27 +01001408 if (list != NULL)
Bram Moolenaar51b0f372017-11-18 18:52:04 +01001409 {
Bram Moolenaar246fe032017-11-19 19:56:27 +01001410 listitem_T *li;
1411 int idx;
Bram Moolenaar51b0f372017-11-18 18:52:04 +01001412
Bram Moolenaar246fe032017-11-19 19:56:27 +01001413 balloon_arraysize = list->lv_len;
Bram Moolenaarc799fe22019-05-28 23:08:19 +02001414 balloon_array = ALLOC_CLEAR_MULT(pumitem_T, list->lv_len);
Bram Moolenaar246fe032017-11-19 19:56:27 +01001415 if (balloon_array == NULL)
1416 return;
Bram Moolenaar7e9f3512020-05-13 22:44:22 +02001417 CHECK_LIST_MATERIALIZE(list);
Bram Moolenaar246fe032017-11-19 19:56:27 +01001418 for (idx = 0, li = list->lv_first; li != NULL; li = li->li_next, ++idx)
1419 {
Bram Moolenaard155d7a2018-12-21 16:04:21 +01001420 char_u *text = tv_get_string_chk(&li->li_tv);
Bram Moolenaar246fe032017-11-19 19:56:27 +01001421
1422 balloon_array[idx].pum_text = vim_strsave(
1423 text == NULL ? (char_u *)"" : text);
1424 }
1425 }
1426 else
1427 balloon_arraysize = split_message(mesg, &balloon_array);
1428
Yegappan Lakshmananf97a2952023-01-18 18:17:48 +00001429 if (balloon_arraysize <= 0)
1430 return;
Bram Moolenaar51b0f372017-11-18 18:52:04 +01001431
Yegappan Lakshmananf97a2952023-01-18 18:17:48 +00001432 pum_array = balloon_array;
1433 pum_size = balloon_arraysize;
1434 pum_compute_size();
1435 pum_scrollbar = 0;
1436 pum_height = balloon_arraysize;
1437
1438 pum_position_at_mouse(BALLOON_MIN_WIDTH);
1439 pum_selected = -1;
1440 pum_first = 0;
1441 pum_redraw();
Bram Moolenaar51b0f372017-11-18 18:52:04 +01001442}
1443
1444/*
1445 * Called when the mouse moved, may remove any displayed balloon.
1446 */
1447 void
1448ui_may_remove_balloon(void)
1449{
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001450 // For now: remove the balloon whenever the mouse moves to another screen
1451 // cell.
1452 ui_remove_balloon();
Bram Moolenaar51b0f372017-11-18 18:52:04 +01001453}
Bram Moolenaare2c453d2019-08-21 14:37:09 +02001454#endif
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01001455
Bram Moolenaare2c453d2019-08-21 14:37:09 +02001456#if defined(FEAT_TERM_POPUP_MENU) || defined(PROTO)
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001457/*
1458 * Select the pum entry at the mouse position.
1459 */
1460 static void
1461pum_select_mouse_pos(void)
1462{
1463 int idx = mouse_row - pum_row;
1464
1465 if (idx < 0 || idx >= pum_size)
1466 pum_selected = -1;
1467 else if (*pum_array[idx].pum_text != NUL)
1468 pum_selected = idx;
1469}
1470
1471/*
1472 * Execute the currently selected popup menu item.
1473 */
1474 static void
Bram Moolenaar987723e2018-03-06 11:43:04 +01001475pum_execute_menu(vimmenu_T *menu, int mode)
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001476{
1477 vimmenu_T *mp;
1478 int idx = 0;
1479 exarg_T ea;
1480
Bram Moolenaar00d253e2020-04-06 22:13:01 +02001481 FOR_ALL_CHILD_MENUS(menu, mp)
Bram Moolenaar987723e2018-03-06 11:43:04 +01001482 if ((mp->modes & mp->enabled & mode) && idx++ == pum_selected)
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001483 {
Bram Moolenaara80faa82020-04-12 19:37:17 +02001484 CLEAR_FIELD(ea);
Bram Moolenaar4c5d8152018-10-19 22:36:53 +02001485 execute_menu(&ea, mp, -1);
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001486 break;
1487 }
1488}
1489
1490/*
1491 * Open the terminal version of the popup menu and don't return until it is
1492 * closed.
1493 */
1494 void
1495pum_show_popupmenu(vimmenu_T *menu)
1496{
1497 vimmenu_T *mp;
1498 int idx = 0;
1499 pumitem_T *array;
Bram Moolenaare2c453d2019-08-21 14:37:09 +02001500# ifdef FEAT_BEVAL_TERM
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001501 int save_bevalterm = p_bevalterm;
Bram Moolenaare2c453d2019-08-21 14:37:09 +02001502# endif
Bram Moolenaar29a2c082018-03-05 21:06:23 +01001503 int mode;
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001504
1505 pum_undisplay();
1506 pum_size = 0;
Bram Moolenaar29a2c082018-03-05 21:06:23 +01001507 mode = get_menu_mode_flag();
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001508
Bram Moolenaar00d253e2020-04-06 22:13:01 +02001509 FOR_ALL_CHILD_MENUS(menu, mp)
Bram Moolenaar29a2c082018-03-05 21:06:23 +01001510 if (menu_is_separator(mp->dname)
1511 || (mp->modes & mp->enabled & mode))
1512 ++pum_size;
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001513
Bram Moolenaarf42b45d2019-01-06 13:11:05 +01001514 // When there are only Terminal mode menus, using "popup Edit" results in
1515 // pum_size being zero.
1516 if (pum_size <= 0)
1517 {
Bram Moolenaar3a846e62022-01-01 16:21:00 +00001518 emsg(e_menu_only_exists_in_another_mode);
Bram Moolenaarf42b45d2019-01-06 13:11:05 +01001519 return;
1520 }
1521
Bram Moolenaarc799fe22019-05-28 23:08:19 +02001522 array = ALLOC_CLEAR_MULT(pumitem_T, pum_size);
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001523 if (array == NULL)
1524 return;
1525
Bram Moolenaar00d253e2020-04-06 22:13:01 +02001526 FOR_ALL_CHILD_MENUS(menu, mp)
Bram Moolenaar38455a92020-12-24 18:39:02 +01001527 {
1528 char_u *s = NULL;
1529
1530 // Make a copy of the text, the menu may be redefined in a callback.
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001531 if (menu_is_separator(mp->dname))
Bram Moolenaar38455a92020-12-24 18:39:02 +01001532 s = (char_u *)"";
Bram Moolenaar29a2c082018-03-05 21:06:23 +01001533 else if (mp->modes & mp->enabled & mode)
Bram Moolenaar38455a92020-12-24 18:39:02 +01001534 s = mp->dname;
1535 if (s != NULL)
1536 {
1537 s = vim_strsave(s);
1538 if (s != NULL)
1539 array[idx++].pum_text = s;
1540 }
1541 }
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001542
1543 pum_array = array;
1544 pum_compute_size();
1545 pum_scrollbar = 0;
1546 pum_height = pum_size;
1547 pum_position_at_mouse(20);
1548
1549 pum_selected = -1;
1550 pum_first = 0;
Bram Moolenaare2c453d2019-08-21 14:37:09 +02001551# ifdef FEAT_BEVAL_TERM
Bram Moolenaar63d9e732019-12-05 21:10:38 +01001552 p_bevalterm = TRUE; // track mouse movement
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001553 mch_setmouse(TRUE);
Bram Moolenaare2c453d2019-08-21 14:37:09 +02001554# endif
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001555
1556 for (;;)
1557 {
1558 int c;
1559
1560 pum_redraw();
Bram Moolenaar987723e2018-03-06 11:43:04 +01001561 setcursor_mayforce(TRUE);
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001562 out_flush();
1563
1564 c = vgetc();
Bram Moolenaar5c3fb042019-05-30 15:53:29 +02001565
zeertzjq92a16782022-07-26 12:24:41 +01001566 // Bail out when typing Esc, CTRL-C or some callback or <expr> mapping
1567 // closed the popup menu.
Bram Moolenaar5c3fb042019-05-30 15:53:29 +02001568 if (c == ESC || c == Ctrl_C || pum_array == NULL)
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001569 break;
1570 else if (c == CAR || c == NL)
1571 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +01001572 // enter: select current item, if any, and close
Bram Moolenaar987723e2018-03-06 11:43:04 +01001573 pum_execute_menu(menu, mode);
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001574 break;
1575 }
1576 else if (c == 'k' || c == K_UP || c == K_MOUSEUP)
1577 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +01001578 // cursor up: select previous item
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001579 while (pum_selected > 0)
1580 {
1581 --pum_selected;
1582 if (*array[pum_selected].pum_text != NUL)
1583 break;
1584 }
1585 }
1586 else if (c == 'j' || c == K_DOWN || c == K_MOUSEDOWN)
1587 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +01001588 // cursor down: select next item
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001589 while (pum_selected < pum_size - 1)
1590 {
1591 ++pum_selected;
1592 if (*array[pum_selected].pum_text != NUL)
1593 break;
1594 }
1595 }
1596 else if (c == K_RIGHTMOUSE)
1597 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +01001598 // Right mouse down: reposition the menu.
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001599 vungetc(c);
1600 break;
1601 }
1602 else if (c == K_LEFTDRAG || c == K_RIGHTDRAG || c == K_MOUSEMOVE)
1603 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +01001604 // mouse moved: select item in the mouse row
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001605 pum_select_mouse_pos();
1606 }
1607 else if (c == K_LEFTMOUSE || c == K_LEFTMOUSE_NM || c == K_RIGHTRELEASE)
1608 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +01001609 // left mouse click: select clicked item, if any, and close;
1610 // right mouse release: select clicked item, close if any
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001611 pum_select_mouse_pos();
1612 if (pum_selected >= 0)
1613 {
Bram Moolenaar987723e2018-03-06 11:43:04 +01001614 pum_execute_menu(menu, mode);
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001615 break;
1616 }
1617 if (c == K_LEFTMOUSE || c == K_LEFTMOUSE_NM)
1618 break;
1619 }
1620 }
1621
Bram Moolenaar38455a92020-12-24 18:39:02 +01001622 for (idx = 0; idx < pum_size; ++idx)
1623 vim_free(array[idx].pum_text);
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001624 vim_free(array);
1625 pum_undisplay();
Bram Moolenaare2c453d2019-08-21 14:37:09 +02001626# ifdef FEAT_BEVAL_TERM
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001627 p_bevalterm = save_bevalterm;
1628 mch_setmouse(TRUE);
Bram Moolenaare2c453d2019-08-21 14:37:09 +02001629# endif
Bram Moolenaaraef8c3d2018-03-03 18:59:16 +01001630}
Bram Moolenaar29a2c082018-03-05 21:06:23 +01001631
1632 void
1633pum_make_popup(char_u *path_name, int use_mouse_pos)
1634{
1635 vimmenu_T *menu;
1636
1637 if (!use_mouse_pos)
1638 {
Bram Moolenaar63d9e732019-12-05 21:10:38 +01001639 // Hack: set mouse position at the cursor so that the menu pops up
1640 // around there.
Bram Moolenaar29a2c082018-03-05 21:06:23 +01001641 mouse_row = curwin->w_winrow + curwin->w_wrow;
1642 mouse_col = curwin->w_wincol + curwin->w_wcol;
1643 }
1644
1645 menu = gui_find_menu(path_name);
1646 if (menu != NULL)
1647 pum_show_popupmenu(menu);
1648}
Bram Moolenaar4b779472005-10-04 09:12:31 +00001649#endif