Mercurial > vim
annotate src/popupmnu.c @ 12178:a1014f647b61 v8.0.0969
patch 8.0.0969: Coverity warning for unused return value
commit https://github.com/vim/vim/commit/dc926dd0dd0ef72fe7993f134f2cc1551cd269ea
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Aug 19 21:26:44 2017 +0200
patch 8.0.0969: Coverity warning for unused return value
Problem: Coverity warning for unused return value.
Solution: Add (void) to avoid the warning.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 19 Aug 2017 21:30:04 +0200 |
parents | 506f5d8b7d8b |
children | 68d7bc045dbe |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
8220
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
800 | 2 * |
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 /* | |
11 * popupmnu.c: Popup menu (PUM) | |
12 */ | |
13 #include "vim.h" | |
14 | |
15 #if defined(FEAT_INS_EXPAND) || defined(PROTO) | |
16 | |
17 static pumitem_T *pum_array = NULL; /* items of displayed pum */ | |
18 static int pum_size; /* nr of items in "pum_array" */ | |
19 static int pum_selected; /* index of selected item or -1 */ | |
20 static int pum_first = 0; /* index of top item */ | |
21 | |
22 static int pum_height; /* nr of displayed pum items */ | |
23 static int pum_width; /* width of displayed pum items */ | |
24 static int pum_base_width; /* width of pum items base */ | |
25 static int pum_kind_width; /* width of pum items kind column */ | |
26 static int pum_scrollbar; /* TRUE when scrollbar present */ | |
27 | |
28 static int pum_row; /* top row of pum */ | |
29 static int pum_col; /* left column of pum */ | |
30 | |
31 static int pum_do_redraw = FALSE; /* do redraw anyway */ | |
32 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7181
diff
changeset
|
33 static int pum_set_selected(int n, int repeat); |
800 | 34 |
35 #define PUM_DEF_HEIGHT 10 | |
36 #define PUM_DEF_WIDTH 15 | |
37 | |
38 /* | |
39 * Show the popup menu with items "array[size]". | |
40 * "array" must remain valid until pum_undisplay() is called! | |
41 * When possible the leftmost character is aligned with screen column "col". | |
42 * The menu appears above the screen line "row" or at "row" + "height" - 1. | |
43 */ | |
44 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
45 pum_display( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
46 pumitem_T *array, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
47 int size, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
48 int selected) /* index of initially selected item, none if |
800 | 49 out of range */ |
50 { | |
51 int w; | |
52 int def_width; | |
53 int max_width; | |
54 int kind_width; | |
55 int extra_width; | |
56 int i; | |
57 int row; | |
1622 | 58 int context_lines; |
800 | 59 int col; |
10326
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
60 int above_row; |
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
61 int below_row; |
838 | 62 int redo_count = 0; |
10332
4d98f501d1c5
commit https://github.com/vim/vim/commit/aab3383e70456f054fe9d0963fe3eb45994aa5e7
Christian Brabandt <cb@256bit.org>
parents:
10326
diff
changeset
|
63 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) |
10326
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
64 win_T *pvwin; |
10332
4d98f501d1c5
commit https://github.com/vim/vim/commit/aab3383e70456f054fe9d0963fe3eb45994aa5e7
Christian Brabandt <cb@256bit.org>
parents:
10326
diff
changeset
|
65 #endif |
800 | 66 |
67 redo: | |
68 def_width = PUM_DEF_WIDTH; | |
69 max_width = 0; | |
70 kind_width = 0; | |
71 extra_width = 0; | |
10326
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
72 above_row = 0; |
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
73 below_row = cmdline_row; |
800 | 74 |
75 /* Pretend the pum is already there to avoid that must_redraw is set when | |
76 * 'cuc' is on. */ | |
77 pum_array = (pumitem_T *)1; | |
78 validate_cursor_col(); | |
79 pum_array = NULL; | |
80 | |
1622 | 81 row = curwin->w_wrow + W_WINROW(curwin); |
800 | 82 |
8220
ad9edad64d22
commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
83 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) |
10326
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
84 FOR_ALL_WINDOWS(pvwin) |
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
85 if (pvwin->w_p_pvw) |
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
86 break; |
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
87 if (pvwin != NULL) |
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
88 { |
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
89 if (W_WINROW(pvwin) < W_WINROW(curwin)) |
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
90 above_row = W_WINROW(pvwin) + pvwin->w_height; |
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
91 else if (W_WINROW(pvwin) > W_WINROW(curwin) + curwin->w_height) |
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
92 below_row = W_WINROW(pvwin); |
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
93 } |
8220
ad9edad64d22
commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
94 #endif |
800 | 95 |
96 /* | |
97 * Figure out the size and position of the pum. | |
98 */ | |
99 if (size < PUM_DEF_HEIGHT) | |
100 pum_height = size; | |
101 else | |
102 pum_height = PUM_DEF_HEIGHT; | |
103 if (p_ph > 0 && pum_height > p_ph) | |
104 pum_height = p_ph; | |
105 | |
106 /* Put the pum below "row" if possible. If there are few lines decide on | |
107 * where there is more room. */ | |
10410
783a75eca83a
commit https://github.com/vim/vim/commit/73095288da839f7c738a49baa109773e76106806
Christian Brabandt <cb@256bit.org>
parents:
10332
diff
changeset
|
108 if (row + 2 >= below_row - pum_height |
783a75eca83a
commit https://github.com/vim/vim/commit/73095288da839f7c738a49baa109773e76106806
Christian Brabandt <cb@256bit.org>
parents:
10332
diff
changeset
|
109 && row - above_row > (below_row - above_row) / 2) |
800 | 110 { |
111 /* pum above "row" */ | |
1622 | 112 |
113 /* Leave two lines of context if possible */ | |
114 if (curwin->w_wrow - curwin->w_cline_row >= 2) | |
115 context_lines = 2; | |
116 else | |
117 context_lines = curwin->w_wrow - curwin->w_cline_row; | |
118 | |
119 if (row >= size + context_lines) | |
800 | 120 { |
1622 | 121 pum_row = row - size - context_lines; |
800 | 122 pum_height = size; |
123 } | |
124 else | |
125 { | |
126 pum_row = 0; | |
1622 | 127 pum_height = row - context_lines; |
800 | 128 } |
129 if (p_ph > 0 && pum_height > p_ph) | |
130 { | |
131 pum_row += pum_height - p_ph; | |
132 pum_height = p_ph; | |
133 } | |
134 } | |
135 else | |
136 { | |
137 /* pum below "row" */ | |
1622 | 138 |
139 /* Leave two lines of context if possible */ | |
140 if (curwin->w_cline_row + curwin->w_cline_height - curwin->w_wrow >= 3) | |
141 context_lines = 3; | |
142 else | |
143 context_lines = curwin->w_cline_row | |
144 + curwin->w_cline_height - curwin->w_wrow; | |
145 | |
146 pum_row = row + context_lines; | |
10326
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
147 if (size > below_row - pum_row) |
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
148 pum_height = below_row - pum_row; |
800 | 149 else |
150 pum_height = size; | |
151 if (p_ph > 0 && pum_height > p_ph) | |
152 pum_height = p_ph; | |
153 } | |
154 | |
155 /* don't display when we only have room for one line */ | |
156 if (pum_height < 1 || (pum_height == 1 && size > 1)) | |
157 return; | |
158 | |
8220
ad9edad64d22
commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
159 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) |
10326
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
160 /* If there is a preview window at the above avoid drawing over it. */ |
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
161 if (pvwin != NULL && pum_row < above_row && pum_height > above_row) |
800 | 162 { |
10326
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
163 pum_row += above_row; |
7d10572eaba4
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents:
10302
diff
changeset
|
164 pum_height -= above_row; |
800 | 165 } |
8220
ad9edad64d22
commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
166 #endif |
800 | 167 |
168 /* Compute the width of the widest match and the widest extra. */ | |
169 for (i = 0; i < size; ++i) | |
170 { | |
171 w = vim_strsize(array[i].pum_text); | |
172 if (max_width < w) | |
173 max_width = w; | |
174 if (array[i].pum_kind != NULL) | |
175 { | |
176 w = vim_strsize(array[i].pum_kind) + 1; | |
177 if (kind_width < w) | |
178 kind_width = w; | |
179 } | |
180 if (array[i].pum_extra != NULL) | |
181 { | |
182 w = vim_strsize(array[i].pum_extra) + 1; | |
183 if (extra_width < w) | |
184 extra_width = w; | |
185 } | |
186 } | |
187 pum_base_width = max_width; | |
188 pum_kind_width = kind_width; | |
189 | |
1344 | 190 /* Calculate column */ |
191 #ifdef FEAT_RIGHTLEFT | |
192 if (curwin->w_p_rl) | |
1668 | 193 col = W_WINCOL(curwin) + W_WIDTH(curwin) - curwin->w_wcol - 1; |
1344 | 194 else |
195 #endif | |
1668 | 196 col = W_WINCOL(curwin) + curwin->w_wcol; |
1344 | 197 |
800 | 198 /* if there are more items than room we need a scrollbar */ |
199 if (pum_height < size) | |
200 { | |
201 pum_scrollbar = 1; | |
202 ++max_width; | |
203 } | |
204 else | |
205 pum_scrollbar = 0; | |
206 | |
207 if (def_width < max_width) | |
208 def_width = max_width; | |
209 | |
1344 | 210 if (((col < Columns - PUM_DEF_WIDTH || col < Columns - max_width) |
211 #ifdef FEAT_RIGHTLEFT | |
212 && !curwin->w_p_rl) | |
213 || (curwin->w_p_rl && (col > PUM_DEF_WIDTH || col > max_width) | |
214 #endif | |
215 )) | |
800 | 216 { |
217 /* align pum column with "col" */ | |
218 pum_col = col; | |
1344 | 219 |
220 #ifdef FEAT_RIGHTLEFT | |
221 if (curwin->w_p_rl) | |
222 pum_width = pum_col - pum_scrollbar + 1; | |
223 else | |
224 #endif | |
225 pum_width = Columns - pum_col - pum_scrollbar; | |
226 | |
800 | 227 if (pum_width > max_width + kind_width + extra_width + 1 |
228 && pum_width > PUM_DEF_WIDTH) | |
229 { | |
230 pum_width = max_width + kind_width + extra_width + 1; | |
231 if (pum_width < PUM_DEF_WIDTH) | |
232 pum_width = PUM_DEF_WIDTH; | |
233 } | |
234 } | |
235 else if (Columns < def_width) | |
236 { | |
237 /* not enough room, will use what we have */ | |
1344 | 238 #ifdef FEAT_RIGHTLEFT |
239 if (curwin->w_p_rl) | |
240 pum_col = Columns - 1; | |
241 else | |
242 #endif | |
243 pum_col = 0; | |
800 | 244 pum_width = Columns - 1; |
245 } | |
246 else | |
247 { | |
248 if (max_width > PUM_DEF_WIDTH) | |
249 max_width = PUM_DEF_WIDTH; /* truncate */ | |
1344 | 250 #ifdef FEAT_RIGHTLEFT |
251 if (curwin->w_p_rl) | |
252 pum_col = max_width - 1; | |
253 else | |
254 #endif | |
255 pum_col = Columns - max_width; | |
800 | 256 pum_width = max_width - pum_scrollbar; |
257 } | |
258 | |
259 pum_array = array; | |
260 pum_size = size; | |
261 | |
262 /* Set selected item and redraw. If the window size changed need to redo | |
838 | 263 * the positioning. Limit this to two times, when there is not much |
264 * room the window size will keep changing. */ | |
265 if (pum_set_selected(selected, redo_count) && ++redo_count <= 2) | |
800 | 266 goto redo; |
267 } | |
268 | |
269 /* | |
270 * Redraw the popup menu, using "pum_first" and "pum_selected". | |
271 */ | |
272 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
273 pum_redraw(void) |
800 | 274 { |
275 int row = pum_row; | |
276 int col; | |
277 int attr_norm = highlight_attr[HLF_PNI]; | |
278 int attr_select = highlight_attr[HLF_PSI]; | |
279 int attr_scroll = highlight_attr[HLF_PSB]; | |
280 int attr_thumb = highlight_attr[HLF_PST]; | |
281 int attr; | |
282 int i; | |
283 int idx; | |
284 char_u *s; | |
285 char_u *p = NULL; | |
286 int totwidth, width, w; | |
287 int thumb_pos = 0; | |
288 int thumb_heigth = 1; | |
289 int round; | |
290 int n; | |
291 | |
5444 | 292 /* Never display more than we have */ |
293 if (pum_first > pum_size - pum_height) | |
294 pum_first = pum_size - pum_height; | |
295 | |
800 | 296 if (pum_scrollbar) |
297 { | |
298 thumb_heigth = pum_height * pum_height / pum_size; | |
299 if (thumb_heigth == 0) | |
300 thumb_heigth = 1; | |
301 thumb_pos = (pum_first * (pum_height - thumb_heigth) | |
302 + (pum_size - pum_height) / 2) | |
303 / (pum_size - pum_height); | |
304 } | |
305 | |
306 for (i = 0; i < pum_height; ++i) | |
307 { | |
308 idx = i + pum_first; | |
309 attr = (idx == pum_selected) ? attr_select : attr_norm; | |
310 | |
311 /* prepend a space if there is room */ | |
1344 | 312 #ifdef FEAT_RIGHTLEFT |
313 if (curwin->w_p_rl) | |
314 { | |
315 if (pum_col < W_WINCOL(curwin) + W_WIDTH(curwin) - 1) | |
316 screen_putchar(' ', row, pum_col + 1, attr); | |
317 } | |
318 else | |
319 #endif | |
320 if (pum_col > 0) | |
321 screen_putchar(' ', row, pum_col - 1, attr); | |
800 | 322 |
323 /* Display each entry, use two spaces for a Tab. | |
324 * Do this 3 times: For the main text, kind and extra info */ | |
325 col = pum_col; | |
326 totwidth = 0; | |
327 for (round = 1; round <= 3; ++round) | |
328 { | |
329 width = 0; | |
330 s = NULL; | |
331 switch (round) | |
332 { | |
333 case 1: p = pum_array[idx].pum_text; break; | |
334 case 2: p = pum_array[idx].pum_kind; break; | |
335 case 3: p = pum_array[idx].pum_extra; break; | |
336 } | |
337 if (p != NULL) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
338 for ( ; ; MB_PTR_ADV(p)) |
800 | 339 { |
340 if (s == NULL) | |
341 s = p; | |
342 w = ptr2cells(p); | |
343 if (*p == NUL || *p == TAB || totwidth + w > pum_width) | |
344 { | |
1097 | 345 /* Display the text that fits or comes before a Tab. |
346 * First convert it to printable characters. */ | |
1344 | 347 char_u *st; |
348 int saved = *p; | |
1097 | 349 |
350 *p = NUL; | |
351 st = transstr(s); | |
352 *p = saved; | |
1344 | 353 #ifdef FEAT_RIGHTLEFT |
354 if (curwin->w_p_rl) | |
1097 | 355 { |
1344 | 356 if (st != NULL) |
357 { | |
358 char_u *rt = reverse_text(st); | |
359 | |
360 if (rt != NULL) | |
361 { | |
2056
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
362 char_u *rt_start = rt; |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
363 int size; |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
364 |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
365 size = vim_strsize(rt); |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
366 if (size > pum_width) |
1344 | 367 { |
2056
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
368 do |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
369 { |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
370 size -= has_mbyte |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
371 ? (*mb_ptr2cells)(rt) : 1; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
372 MB_PTR_ADV(rt); |
2056
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
373 } while (size > pum_width); |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
374 |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
375 if (size < pum_width) |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
376 { |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
377 /* Most left character requires |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
378 * 2-cells but only 1 cell is |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
379 * available on screen. Put a |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
380 * '<' on the left of the pum |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
381 * item */ |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
382 *(--rt) = '<'; |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
383 size++; |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
384 } |
1344 | 385 } |
2056
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
386 screen_puts_len(rt, (int)STRLEN(rt), |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
387 row, col - size + 1, attr); |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
388 vim_free(rt_start); |
1344 | 389 } |
390 vim_free(st); | |
391 } | |
392 col -= width; | |
393 } | |
394 else | |
395 #endif | |
396 { | |
397 if (st != NULL) | |
398 { | |
399 screen_puts_len(st, (int)STRLEN(st), row, col, | |
1097 | 400 attr); |
1344 | 401 vim_free(st); |
402 } | |
403 col += width; | |
1097 | 404 } |
800 | 405 |
406 if (*p != TAB) | |
407 break; | |
408 | |
409 /* Display two spaces for a Tab. */ | |
1344 | 410 #ifdef FEAT_RIGHTLEFT |
411 if (curwin->w_p_rl) | |
412 { | |
413 screen_puts_len((char_u *)" ", 2, row, col - 1, | |
414 attr); | |
415 col -= 2; | |
416 } | |
417 else | |
418 #endif | |
419 { | |
420 screen_puts_len((char_u *)" ", 2, row, col, attr); | |
421 col += 2; | |
422 } | |
800 | 423 totwidth += 2; |
424 s = NULL; /* start text at next char */ | |
425 width = 0; | |
426 } | |
427 else | |
428 width += w; | |
429 } | |
430 | |
431 if (round > 1) | |
432 n = pum_kind_width + 1; | |
433 else | |
434 n = 1; | |
435 | |
436 /* Stop when there is nothing more to display. */ | |
437 if (round == 3 | |
438 || (round == 2 && pum_array[idx].pum_extra == NULL) | |
439 || (round == 1 && pum_array[idx].pum_kind == NULL | |
440 && pum_array[idx].pum_extra == NULL) | |
441 || pum_base_width + n >= pum_width) | |
442 break; | |
1344 | 443 #ifdef FEAT_RIGHTLEFT |
444 if (curwin->w_p_rl) | |
445 { | |
446 screen_fill(row, row + 1, pum_col - pum_base_width - n + 1, | |
447 col + 1, ' ', ' ', attr); | |
448 col = pum_col - pum_base_width - n + 1; | |
449 } | |
450 else | |
451 #endif | |
452 { | |
453 screen_fill(row, row + 1, col, pum_col + pum_base_width + n, | |
800 | 454 ' ', ' ', attr); |
1344 | 455 col = pum_col + pum_base_width + n; |
456 } | |
800 | 457 totwidth = pum_base_width + n; |
458 } | |
459 | |
1344 | 460 #ifdef FEAT_RIGHTLEFT |
461 if (curwin->w_p_rl) | |
462 screen_fill(row, row + 1, pum_col - pum_width + 1, col + 1, ' ', | |
463 ' ', attr); | |
464 else | |
465 #endif | |
466 screen_fill(row, row + 1, col, pum_col + pum_width, ' ', ' ', | |
467 attr); | |
800 | 468 if (pum_scrollbar > 0) |
1344 | 469 { |
470 #ifdef FEAT_RIGHTLEFT | |
471 if (curwin->w_p_rl) | |
472 screen_putchar(' ', row, pum_col - pum_width, | |
473 i >= thumb_pos && i < thumb_pos + thumb_heigth | |
800 | 474 ? attr_thumb : attr_scroll); |
1344 | 475 else |
476 #endif | |
477 screen_putchar(' ', row, pum_col + pum_width, | |
478 i >= thumb_pos && i < thumb_pos + thumb_heigth | |
479 ? attr_thumb : attr_scroll); | |
480 } | |
800 | 481 |
482 ++row; | |
483 } | |
484 } | |
485 | |
486 /* | |
487 * Set the index of the currently selected item. The menu will scroll when | |
488 * necessary. When "n" is out of range don't scroll. | |
838 | 489 * This may be repeated when the preview window is used: |
490 * "repeat" == 0: open preview window normally | |
491 * "repeat" == 1: open preview window but don't set the size | |
492 * "repeat" == 2: don't open preview window | |
800 | 493 * Returns TRUE when the window was resized and the location of the popup menu |
494 * must be recomputed. | |
495 */ | |
496 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
497 pum_set_selected(int n, int repeat) |
800 | 498 { |
499 int resized = FALSE; | |
500 int context = pum_height / 2; | |
501 | |
502 pum_selected = n; | |
503 | |
504 if (pum_selected >= 0 && pum_selected < pum_size) | |
505 { | |
506 if (pum_first > pum_selected - 4) | |
507 { | |
508 /* scroll down; when we did a jump it's probably a PageUp then | |
509 * scroll a whole page */ | |
510 if (pum_first > pum_selected - 2) | |
511 { | |
512 pum_first -= pum_height - 2; | |
513 if (pum_first < 0) | |
514 pum_first = 0; | |
515 else if (pum_first > pum_selected) | |
516 pum_first = pum_selected; | |
517 } | |
518 else | |
519 pum_first = pum_selected; | |
520 } | |
521 else if (pum_first < pum_selected - pum_height + 5) | |
522 { | |
523 /* scroll up; when we did a jump it's probably a PageDown then | |
524 * scroll a whole page */ | |
525 if (pum_first < pum_selected - pum_height + 1 + 2) | |
526 { | |
527 pum_first += pum_height - 2; | |
528 if (pum_first < pum_selected - pum_height + 1) | |
529 pum_first = pum_selected - pum_height + 1; | |
530 } | |
531 else | |
532 pum_first = pum_selected - pum_height + 1; | |
533 } | |
534 | |
535 /* Give a few lines of context when possible. */ | |
536 if (context > 3) | |
537 context = 3; | |
538 if (pum_height > 2) | |
539 { | |
540 if (pum_first > pum_selected - context) | |
541 { | |
542 /* scroll down */ | |
543 pum_first = pum_selected - context; | |
544 if (pum_first < 0) | |
545 pum_first = 0; | |
546 } | |
547 else if (pum_first < pum_selected + context - pum_height + 1) | |
548 { | |
549 /* scroll up */ | |
550 pum_first = pum_selected + context - pum_height + 1; | |
551 } | |
552 } | |
553 | |
554 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
816 | 555 /* |
556 * Show extra info in the preview window if there is something and | |
557 * 'completeopt' contains "preview". | |
838 | 558 * Skip this when tried twice already. |
559 * Skip this also when there is not much room. | |
816 | 560 * NOTE: Be very careful not to sync undo! |
561 */ | |
800 | 562 if (pum_array[pum_selected].pum_info != NULL |
838 | 563 && Rows > 10 |
564 && repeat <= 1 | |
565 && vim_strchr(p_cot, 'p') != NULL) | |
800 | 566 { |
567 win_T *curwin_save = curwin; | |
568 int res = OK; | |
569 | |
2622 | 570 /* Open a preview window. 3 lines by default. Prefer |
571 * 'previewheight' if set and smaller. */ | |
800 | 572 g_do_tagpreview = 3; |
2622 | 573 if (p_pvh > 0 && p_pvh < g_do_tagpreview) |
574 g_do_tagpreview = p_pvh; | |
6043 | 575 ++RedrawingDisabled; |
7181
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
576 /* Prevent undo sync here, if an autocommand syncs undo weird |
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
577 * things can happen to the undo tree. */ |
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
578 ++no_u_sync; |
816 | 579 resized = prepare_tagpreview(FALSE); |
7181
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
580 --no_u_sync; |
6043 | 581 --RedrawingDisabled; |
800 | 582 g_do_tagpreview = 0; |
583 | |
584 if (curwin->w_p_pvw) | |
585 { | |
10302
210af8588e8a
commit https://github.com/vim/vim/commit/50e5376926dc2ec4a26a7a16f8f0f3213c4afdf0
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
586 if (!resized |
210af8588e8a
commit https://github.com/vim/vim/commit/50e5376926dc2ec4a26a7a16f8f0f3213c4afdf0
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
587 && curbuf->b_nwindows == 1 |
210af8588e8a
commit https://github.com/vim/vim/commit/50e5376926dc2ec4a26a7a16f8f0f3213c4afdf0
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
588 && curbuf->b_fname == NULL |
800 | 589 && curbuf->b_p_bt[0] == 'n' && curbuf->b_p_bt[2] == 'f' |
590 && curbuf->b_p_bh[0] == 'w') | |
591 { | |
592 /* Already a "wipeout" buffer, make it empty. */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10410
diff
changeset
|
593 while (!BUFEMPTY()) |
800 | 594 ml_delete((linenr_T)1, FALSE); |
595 } | |
825 | 596 else |
800 | 597 { |
825 | 598 /* Don't want to sync undo in the current buffer. */ |
599 ++no_u_sync; | |
1743 | 600 res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0, NULL); |
825 | 601 --no_u_sync; |
602 if (res == OK) | |
603 { | |
604 /* Edit a new, empty buffer. Set options for a "wipeout" | |
605 * buffer. */ | |
606 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL); | |
607 set_option_value((char_u *)"bt", 0L, | |
608 (char_u *)"nofile", OPT_LOCAL); | |
609 set_option_value((char_u *)"bh", 0L, | |
610 (char_u *)"wipe", OPT_LOCAL); | |
611 set_option_value((char_u *)"diff", 0L, | |
1302 | 612 NULL, OPT_LOCAL); |
825 | 613 } |
800 | 614 } |
615 if (res == OK) | |
616 { | |
617 char_u *p, *e; | |
618 linenr_T lnum = 0; | |
619 | |
620 for (p = pum_array[pum_selected].pum_info; *p != NUL; ) | |
621 { | |
622 e = vim_strchr(p, '\n'); | |
623 if (e == NULL) | |
624 { | |
625 ml_append(lnum++, p, 0, FALSE); | |
626 break; | |
627 } | |
628 else | |
629 { | |
630 *e = NUL; | |
835 | 631 ml_append(lnum++, p, (int)(e - p + 1), FALSE); |
800 | 632 *e = '\n'; |
633 p = e + 1; | |
634 } | |
635 } | |
636 | |
637 /* Increase the height of the preview window to show the | |
638 * text, but no more than 'previewheight' lines. */ | |
838 | 639 if (repeat == 0) |
800 | 640 { |
838 | 641 if (lnum > p_pvh) |
642 lnum = p_pvh; | |
643 if (curwin->w_height < lnum) | |
644 { | |
645 win_setheight((int)lnum); | |
646 resized = TRUE; | |
647 } | |
800 | 648 } |
649 | |
650 curbuf->b_changed = 0; | |
651 curbuf->b_p_ma = FALSE; | |
2113
85ad19790706
updated for version 7.2.396
Bram Moolenaar <bram@zimbu.org>
parents:
2056
diff
changeset
|
652 curwin->w_cursor.lnum = 1; |
800 | 653 curwin->w_cursor.col = 0; |
654 | |
655 if (curwin != curwin_save && win_valid(curwin_save)) | |
656 { | |
6089 | 657 /* When the first completion is done and the preview |
658 * window is not resized, skip the preview window's | |
659 * status line redrawing. */ | |
660 if (ins_compl_active() && !resized) | |
661 curwin->w_redr_status = FALSE; | |
662 | |
800 | 663 /* Return cursor to where we were */ |
664 validate_cursor(); | |
665 redraw_later(SOME_VALID); | |
666 | |
667 /* When the preview window was resized we need to | |
668 * update the view on the buffer. Only go back to | |
669 * the window when needed, otherwise it will always be | |
670 * redraw. */ | |
671 if (resized) | |
672 { | |
7181
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
673 ++no_u_sync; |
800 | 674 win_enter(curwin_save, TRUE); |
7181
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
675 --no_u_sync; |
800 | 676 update_topline(); |
677 } | |
678 | |
679 /* Update the screen before drawing the popup menu. | |
680 * Enable updating the status lines. */ | |
681 pum_do_redraw = TRUE; | |
682 update_screen(0); | |
683 pum_do_redraw = FALSE; | |
684 | |
816 | 685 if (!resized && win_valid(curwin_save)) |
7181
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
686 { |
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
687 ++no_u_sync; |
800 | 688 win_enter(curwin_save, TRUE); |
7181
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
689 --no_u_sync; |
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
690 } |
800 | 691 |
692 /* May need to update the screen again when there are | |
693 * autocommands involved. */ | |
694 pum_do_redraw = TRUE; | |
695 update_screen(0); | |
696 pum_do_redraw = FALSE; | |
697 } | |
698 } | |
699 } | |
700 } | |
701 #endif | |
702 } | |
703 | |
704 if (!resized) | |
705 pum_redraw(); | |
706 | |
707 return resized; | |
708 } | |
709 | |
710 /* | |
711 * Undisplay the popup menu (later). | |
712 */ | |
713 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
714 pum_undisplay(void) |
800 | 715 { |
716 pum_array = NULL; | |
717 redraw_all_later(SOME_VALID); | |
940 | 718 #ifdef FEAT_WINDOWS |
719 redraw_tabline = TRUE; | |
720 #endif | |
800 | 721 status_redraw_all(); |
722 } | |
723 | |
724 /* | |
725 * Clear the popup menu. Currently only resets the offset to the first | |
726 * displayed item. | |
727 */ | |
728 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
729 pum_clear(void) |
800 | 730 { |
731 pum_first = 0; | |
732 } | |
733 | |
734 /* | |
735 * Return TRUE if the popup menu is displayed. | |
736 * Overruled when "pum_do_redraw" is set, used to redraw the status lines. | |
737 */ | |
738 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
739 pum_visible(void) |
800 | 740 { |
741 return !pum_do_redraw && pum_array != NULL; | |
742 } | |
743 | |
744 /* | |
745 * Return the height of the popup menu, the number of entries visible. | |
746 * Only valid when pum_visible() returns TRUE! | |
747 */ | |
748 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
749 pum_get_height(void) |
800 | 750 { |
751 return pum_height; | |
752 } | |
753 | |
754 #endif |