Mercurial > vim
annotate src/popupmnu.c @ 7637:81f94c1e2e4d v7.4.1118
commit https://github.com/vim/vim/commit/a99b90437af730dcafd9143c0942c87777a00d52
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 17 17:10:59 2016 +0100
patch 7.4.1118
Problem: Tests hang in 24 line terminal.
Solution: Set the 'more' option off.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 17 Jan 2016 17:15:05 +0100 |
parents | ce8b286e89ef |
children | 0b6c37dd858d |
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 | |
838 | 33 static int pum_set_selected __ARGS((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 | |
45 pum_display(array, size, selected) | |
46 pumitem_T *array; | |
47 int size; | |
48 int selected; /* index of initially selected item, none if | |
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 | |
266 pum_redraw() | |
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 | |
838 | 490 pum_set_selected(n, repeat) |
800 | 491 int n; |
838 | 492 int repeat; |
800 | 493 { |
494 int resized = FALSE; | |
495 int context = pum_height / 2; | |
496 | |
497 pum_selected = n; | |
498 | |
499 if (pum_selected >= 0 && pum_selected < pum_size) | |
500 { | |
501 if (pum_first > pum_selected - 4) | |
502 { | |
503 /* scroll down; when we did a jump it's probably a PageUp then | |
504 * scroll a whole page */ | |
505 if (pum_first > pum_selected - 2) | |
506 { | |
507 pum_first -= pum_height - 2; | |
508 if (pum_first < 0) | |
509 pum_first = 0; | |
510 else if (pum_first > pum_selected) | |
511 pum_first = pum_selected; | |
512 } | |
513 else | |
514 pum_first = pum_selected; | |
515 } | |
516 else if (pum_first < pum_selected - pum_height + 5) | |
517 { | |
518 /* scroll up; when we did a jump it's probably a PageDown then | |
519 * scroll a whole page */ | |
520 if (pum_first < pum_selected - pum_height + 1 + 2) | |
521 { | |
522 pum_first += pum_height - 2; | |
523 if (pum_first < pum_selected - pum_height + 1) | |
524 pum_first = pum_selected - pum_height + 1; | |
525 } | |
526 else | |
527 pum_first = pum_selected - pum_height + 1; | |
528 } | |
529 | |
530 /* Give a few lines of context when possible. */ | |
531 if (context > 3) | |
532 context = 3; | |
533 if (pum_height > 2) | |
534 { | |
535 if (pum_first > pum_selected - context) | |
536 { | |
537 /* scroll down */ | |
538 pum_first = pum_selected - context; | |
539 if (pum_first < 0) | |
540 pum_first = 0; | |
541 } | |
542 else if (pum_first < pum_selected + context - pum_height + 1) | |
543 { | |
544 /* scroll up */ | |
545 pum_first = pum_selected + context - pum_height + 1; | |
546 } | |
547 } | |
548 | |
549 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
816 | 550 /* |
551 * Show extra info in the preview window if there is something and | |
552 * 'completeopt' contains "preview". | |
838 | 553 * Skip this when tried twice already. |
554 * Skip this also when there is not much room. | |
816 | 555 * NOTE: Be very careful not to sync undo! |
556 */ | |
800 | 557 if (pum_array[pum_selected].pum_info != NULL |
838 | 558 && Rows > 10 |
559 && repeat <= 1 | |
560 && vim_strchr(p_cot, 'p') != NULL) | |
800 | 561 { |
562 win_T *curwin_save = curwin; | |
563 int res = OK; | |
564 | |
2622 | 565 /* Open a preview window. 3 lines by default. Prefer |
566 * 'previewheight' if set and smaller. */ | |
800 | 567 g_do_tagpreview = 3; |
2622 | 568 if (p_pvh > 0 && p_pvh < g_do_tagpreview) |
569 g_do_tagpreview = p_pvh; | |
6043 | 570 ++RedrawingDisabled; |
7181
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
571 /* 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
|
572 * 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
|
573 ++no_u_sync; |
816 | 574 resized = prepare_tagpreview(FALSE); |
7181
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
575 --no_u_sync; |
6043 | 576 --RedrawingDisabled; |
800 | 577 g_do_tagpreview = 0; |
578 | |
579 if (curwin->w_p_pvw) | |
580 { | |
581 if (curbuf->b_fname == NULL | |
582 && curbuf->b_p_bt[0] == 'n' && curbuf->b_p_bt[2] == 'f' | |
583 && curbuf->b_p_bh[0] == 'w') | |
584 { | |
585 /* Already a "wipeout" buffer, make it empty. */ | |
586 while (!bufempty()) | |
587 ml_delete((linenr_T)1, FALSE); | |
588 } | |
825 | 589 else |
800 | 590 { |
825 | 591 /* Don't want to sync undo in the current buffer. */ |
592 ++no_u_sync; | |
1743 | 593 res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0, NULL); |
825 | 594 --no_u_sync; |
595 if (res == OK) | |
596 { | |
597 /* Edit a new, empty buffer. Set options for a "wipeout" | |
598 * buffer. */ | |
599 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL); | |
600 set_option_value((char_u *)"bt", 0L, | |
601 (char_u *)"nofile", OPT_LOCAL); | |
602 set_option_value((char_u *)"bh", 0L, | |
603 (char_u *)"wipe", OPT_LOCAL); | |
604 set_option_value((char_u *)"diff", 0L, | |
1302 | 605 NULL, OPT_LOCAL); |
825 | 606 } |
800 | 607 } |
608 if (res == OK) | |
609 { | |
610 char_u *p, *e; | |
611 linenr_T lnum = 0; | |
612 | |
613 for (p = pum_array[pum_selected].pum_info; *p != NUL; ) | |
614 { | |
615 e = vim_strchr(p, '\n'); | |
616 if (e == NULL) | |
617 { | |
618 ml_append(lnum++, p, 0, FALSE); | |
619 break; | |
620 } | |
621 else | |
622 { | |
623 *e = NUL; | |
835 | 624 ml_append(lnum++, p, (int)(e - p + 1), FALSE); |
800 | 625 *e = '\n'; |
626 p = e + 1; | |
627 } | |
628 } | |
629 | |
630 /* Increase the height of the preview window to show the | |
631 * text, but no more than 'previewheight' lines. */ | |
838 | 632 if (repeat == 0) |
800 | 633 { |
838 | 634 if (lnum > p_pvh) |
635 lnum = p_pvh; | |
636 if (curwin->w_height < lnum) | |
637 { | |
638 win_setheight((int)lnum); | |
639 resized = TRUE; | |
640 } | |
800 | 641 } |
642 | |
643 curbuf->b_changed = 0; | |
644 curbuf->b_p_ma = FALSE; | |
2113
85ad19790706
updated for version 7.2.396
Bram Moolenaar <bram@zimbu.org>
parents:
2056
diff
changeset
|
645 curwin->w_cursor.lnum = 1; |
800 | 646 curwin->w_cursor.col = 0; |
647 | |
648 if (curwin != curwin_save && win_valid(curwin_save)) | |
649 { | |
6089 | 650 /* When the first completion is done and the preview |
651 * window is not resized, skip the preview window's | |
652 * status line redrawing. */ | |
653 if (ins_compl_active() && !resized) | |
654 curwin->w_redr_status = FALSE; | |
655 | |
800 | 656 /* Return cursor to where we were */ |
657 validate_cursor(); | |
658 redraw_later(SOME_VALID); | |
659 | |
660 /* When the preview window was resized we need to | |
661 * update the view on the buffer. Only go back to | |
662 * the window when needed, otherwise it will always be | |
663 * redraw. */ | |
664 if (resized) | |
665 { | |
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 win_enter(curwin_save, TRUE); |
7181
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
668 --no_u_sync; |
800 | 669 update_topline(); |
670 } | |
671 | |
672 /* Update the screen before drawing the popup menu. | |
673 * Enable updating the status lines. */ | |
674 pum_do_redraw = TRUE; | |
675 update_screen(0); | |
676 pum_do_redraw = FALSE; | |
677 | |
816 | 678 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
|
679 { |
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
680 ++no_u_sync; |
800 | 681 win_enter(curwin_save, TRUE); |
7181
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
682 --no_u_sync; |
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
683 } |
800 | 684 |
685 /* May need to update the screen again when there are | |
686 * autocommands involved. */ | |
687 pum_do_redraw = TRUE; | |
688 update_screen(0); | |
689 pum_do_redraw = FALSE; | |
690 } | |
691 } | |
692 } | |
693 } | |
694 #endif | |
695 } | |
696 | |
697 if (!resized) | |
698 pum_redraw(); | |
699 | |
700 return resized; | |
701 } | |
702 | |
703 /* | |
704 * Undisplay the popup menu (later). | |
705 */ | |
706 void | |
707 pum_undisplay() | |
708 { | |
709 pum_array = NULL; | |
710 redraw_all_later(SOME_VALID); | |
940 | 711 #ifdef FEAT_WINDOWS |
712 redraw_tabline = TRUE; | |
713 #endif | |
800 | 714 status_redraw_all(); |
715 } | |
716 | |
717 /* | |
718 * Clear the popup menu. Currently only resets the offset to the first | |
719 * displayed item. | |
720 */ | |
721 void | |
722 pum_clear() | |
723 { | |
724 pum_first = 0; | |
725 } | |
726 | |
727 /* | |
728 * Return TRUE if the popup menu is displayed. | |
729 * Overruled when "pum_do_redraw" is set, used to redraw the status lines. | |
730 */ | |
731 int | |
732 pum_visible() | |
733 { | |
734 return !pum_do_redraw && pum_array != NULL; | |
735 } | |
736 | |
737 /* | |
738 * Return the height of the popup menu, the number of entries visible. | |
739 * Only valid when pum_visible() returns TRUE! | |
740 */ | |
741 int | |
742 pum_get_height() | |
743 { | |
744 return pum_height; | |
745 } | |
746 | |
747 #endif |