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