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