Mercurial > vim
annotate src/popupmnu.c @ 2559:7850c8c12347 vim73
Cleanup in :find completion code. Make it work for "./subdir" in 'path'.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Fri, 13 Aug 2010 21:16:49 +0200 |
parents | 6768ebd0bc04 |
children | b2cfe84c96cc |
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 | |
285 if (pum_scrollbar) | |
286 { | |
287 thumb_heigth = pum_height * pum_height / pum_size; | |
288 if (thumb_heigth == 0) | |
289 thumb_heigth = 1; | |
290 thumb_pos = (pum_first * (pum_height - thumb_heigth) | |
291 + (pum_size - pum_height) / 2) | |
292 / (pum_size - pum_height); | |
293 } | |
294 | |
295 for (i = 0; i < pum_height; ++i) | |
296 { | |
297 idx = i + pum_first; | |
298 attr = (idx == pum_selected) ? attr_select : attr_norm; | |
299 | |
300 /* prepend a space if there is room */ | |
1344 | 301 #ifdef FEAT_RIGHTLEFT |
302 if (curwin->w_p_rl) | |
303 { | |
304 if (pum_col < W_WINCOL(curwin) + W_WIDTH(curwin) - 1) | |
305 screen_putchar(' ', row, pum_col + 1, attr); | |
306 } | |
307 else | |
308 #endif | |
309 if (pum_col > 0) | |
310 screen_putchar(' ', row, pum_col - 1, attr); | |
800 | 311 |
312 /* Display each entry, use two spaces for a Tab. | |
313 * Do this 3 times: For the main text, kind and extra info */ | |
314 col = pum_col; | |
315 totwidth = 0; | |
316 for (round = 1; round <= 3; ++round) | |
317 { | |
318 width = 0; | |
319 s = NULL; | |
320 switch (round) | |
321 { | |
322 case 1: p = pum_array[idx].pum_text; break; | |
323 case 2: p = pum_array[idx].pum_kind; break; | |
324 case 3: p = pum_array[idx].pum_extra; break; | |
325 } | |
326 if (p != NULL) | |
327 for ( ; ; mb_ptr_adv(p)) | |
328 { | |
329 if (s == NULL) | |
330 s = p; | |
331 w = ptr2cells(p); | |
332 if (*p == NUL || *p == TAB || totwidth + w > pum_width) | |
333 { | |
1097 | 334 /* Display the text that fits or comes before a Tab. |
335 * First convert it to printable characters. */ | |
1344 | 336 char_u *st; |
337 int saved = *p; | |
1097 | 338 |
339 *p = NUL; | |
340 st = transstr(s); | |
341 *p = saved; | |
1344 | 342 #ifdef FEAT_RIGHTLEFT |
343 if (curwin->w_p_rl) | |
1097 | 344 { |
1344 | 345 if (st != NULL) |
346 { | |
347 char_u *rt = reverse_text(st); | |
348 | |
349 if (rt != NULL) | |
350 { | |
2056
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
351 char_u *rt_start = rt; |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
352 int size; |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
353 |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
354 size = vim_strsize(rt); |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
355 if (size > pum_width) |
1344 | 356 { |
2056
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
357 do |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
358 { |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
359 size -= has_mbyte |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
360 ? (*mb_ptr2cells)(rt) : 1; |
1344 | 361 mb_ptr_adv(rt); |
2056
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
362 } while (size > pum_width); |
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 if (size < pum_width) |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
365 { |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
366 /* Most left character requires |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
367 * 2-cells but only 1 cell is |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
368 * available on screen. Put a |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
369 * '<' on the left of the pum |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
370 * item */ |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
371 *(--rt) = '<'; |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
372 size++; |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
373 } |
1344 | 374 } |
2056
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
375 screen_puts_len(rt, (int)STRLEN(rt), |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
376 row, col - size + 1, attr); |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
377 vim_free(rt_start); |
1344 | 378 } |
379 vim_free(st); | |
380 } | |
381 col -= width; | |
382 } | |
383 else | |
384 #endif | |
385 { | |
386 if (st != NULL) | |
387 { | |
388 screen_puts_len(st, (int)STRLEN(st), row, col, | |
1097 | 389 attr); |
1344 | 390 vim_free(st); |
391 } | |
392 col += width; | |
1097 | 393 } |
800 | 394 |
395 if (*p != TAB) | |
396 break; | |
397 | |
398 /* Display two spaces for a Tab. */ | |
1344 | 399 #ifdef FEAT_RIGHTLEFT |
400 if (curwin->w_p_rl) | |
401 { | |
402 screen_puts_len((char_u *)" ", 2, row, col - 1, | |
403 attr); | |
404 col -= 2; | |
405 } | |
406 else | |
407 #endif | |
408 { | |
409 screen_puts_len((char_u *)" ", 2, row, col, attr); | |
410 col += 2; | |
411 } | |
800 | 412 totwidth += 2; |
413 s = NULL; /* start text at next char */ | |
414 width = 0; | |
415 } | |
416 else | |
417 width += w; | |
418 } | |
419 | |
420 if (round > 1) | |
421 n = pum_kind_width + 1; | |
422 else | |
423 n = 1; | |
424 | |
425 /* Stop when there is nothing more to display. */ | |
426 if (round == 3 | |
427 || (round == 2 && pum_array[idx].pum_extra == NULL) | |
428 || (round == 1 && pum_array[idx].pum_kind == NULL | |
429 && pum_array[idx].pum_extra == NULL) | |
430 || pum_base_width + n >= pum_width) | |
431 break; | |
1344 | 432 #ifdef FEAT_RIGHTLEFT |
433 if (curwin->w_p_rl) | |
434 { | |
435 screen_fill(row, row + 1, pum_col - pum_base_width - n + 1, | |
436 col + 1, ' ', ' ', attr); | |
437 col = pum_col - pum_base_width - n + 1; | |
438 } | |
439 else | |
440 #endif | |
441 { | |
442 screen_fill(row, row + 1, col, pum_col + pum_base_width + n, | |
800 | 443 ' ', ' ', attr); |
1344 | 444 col = pum_col + pum_base_width + n; |
445 } | |
800 | 446 totwidth = pum_base_width + n; |
447 } | |
448 | |
1344 | 449 #ifdef FEAT_RIGHTLEFT |
450 if (curwin->w_p_rl) | |
451 screen_fill(row, row + 1, pum_col - pum_width + 1, col + 1, ' ', | |
452 ' ', attr); | |
453 else | |
454 #endif | |
455 screen_fill(row, row + 1, col, pum_col + pum_width, ' ', ' ', | |
456 attr); | |
800 | 457 if (pum_scrollbar > 0) |
1344 | 458 { |
459 #ifdef FEAT_RIGHTLEFT | |
460 if (curwin->w_p_rl) | |
461 screen_putchar(' ', row, pum_col - pum_width, | |
462 i >= thumb_pos && i < thumb_pos + thumb_heigth | |
800 | 463 ? attr_thumb : attr_scroll); |
1344 | 464 else |
465 #endif | |
466 screen_putchar(' ', row, pum_col + pum_width, | |
467 i >= thumb_pos && i < thumb_pos + thumb_heigth | |
468 ? attr_thumb : attr_scroll); | |
469 } | |
800 | 470 |
471 ++row; | |
472 } | |
473 } | |
474 | |
475 /* | |
476 * Set the index of the currently selected item. The menu will scroll when | |
477 * necessary. When "n" is out of range don't scroll. | |
838 | 478 * This may be repeated when the preview window is used: |
479 * "repeat" == 0: open preview window normally | |
480 * "repeat" == 1: open preview window but don't set the size | |
481 * "repeat" == 2: don't open preview window | |
800 | 482 * Returns TRUE when the window was resized and the location of the popup menu |
483 * must be recomputed. | |
484 */ | |
485 static int | |
838 | 486 pum_set_selected(n, repeat) |
800 | 487 int n; |
838 | 488 int repeat; |
800 | 489 { |
490 int resized = FALSE; | |
491 int context = pum_height / 2; | |
492 | |
493 pum_selected = n; | |
494 | |
495 if (pum_selected >= 0 && pum_selected < pum_size) | |
496 { | |
497 if (pum_first > pum_selected - 4) | |
498 { | |
499 /* scroll down; when we did a jump it's probably a PageUp then | |
500 * scroll a whole page */ | |
501 if (pum_first > pum_selected - 2) | |
502 { | |
503 pum_first -= pum_height - 2; | |
504 if (pum_first < 0) | |
505 pum_first = 0; | |
506 else if (pum_first > pum_selected) | |
507 pum_first = pum_selected; | |
508 } | |
509 else | |
510 pum_first = pum_selected; | |
511 } | |
512 else if (pum_first < pum_selected - pum_height + 5) | |
513 { | |
514 /* scroll up; when we did a jump it's probably a PageDown then | |
515 * scroll a whole page */ | |
516 if (pum_first < pum_selected - pum_height + 1 + 2) | |
517 { | |
518 pum_first += pum_height - 2; | |
519 if (pum_first < pum_selected - pum_height + 1) | |
520 pum_first = pum_selected - pum_height + 1; | |
521 } | |
522 else | |
523 pum_first = pum_selected - pum_height + 1; | |
524 } | |
525 | |
526 /* Give a few lines of context when possible. */ | |
527 if (context > 3) | |
528 context = 3; | |
529 if (pum_height > 2) | |
530 { | |
531 if (pum_first > pum_selected - context) | |
532 { | |
533 /* scroll down */ | |
534 pum_first = pum_selected - context; | |
535 if (pum_first < 0) | |
536 pum_first = 0; | |
537 } | |
538 else if (pum_first < pum_selected + context - pum_height + 1) | |
539 { | |
540 /* scroll up */ | |
541 pum_first = pum_selected + context - pum_height + 1; | |
542 } | |
543 } | |
544 | |
545 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
816 | 546 /* |
547 * Show extra info in the preview window if there is something and | |
548 * 'completeopt' contains "preview". | |
838 | 549 * Skip this when tried twice already. |
550 * Skip this also when there is not much room. | |
816 | 551 * NOTE: Be very careful not to sync undo! |
552 */ | |
800 | 553 if (pum_array[pum_selected].pum_info != NULL |
838 | 554 && Rows > 10 |
555 && repeat <= 1 | |
556 && vim_strchr(p_cot, 'p') != NULL) | |
800 | 557 { |
558 win_T *curwin_save = curwin; | |
559 int res = OK; | |
560 | |
561 /* Open a preview window. 3 lines by default. */ | |
562 g_do_tagpreview = 3; | |
816 | 563 resized = prepare_tagpreview(FALSE); |
800 | 564 g_do_tagpreview = 0; |
565 | |
566 if (curwin->w_p_pvw) | |
567 { | |
568 if (curbuf->b_fname == NULL | |
569 && curbuf->b_p_bt[0] == 'n' && curbuf->b_p_bt[2] == 'f' | |
570 && curbuf->b_p_bh[0] == 'w') | |
571 { | |
572 /* Already a "wipeout" buffer, make it empty. */ | |
573 while (!bufempty()) | |
574 ml_delete((linenr_T)1, FALSE); | |
575 } | |
825 | 576 else |
800 | 577 { |
825 | 578 /* Don't want to sync undo in the current buffer. */ |
579 ++no_u_sync; | |
1743 | 580 res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0, NULL); |
825 | 581 --no_u_sync; |
582 if (res == OK) | |
583 { | |
584 /* Edit a new, empty buffer. Set options for a "wipeout" | |
585 * buffer. */ | |
586 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL); | |
587 set_option_value((char_u *)"bt", 0L, | |
588 (char_u *)"nofile", OPT_LOCAL); | |
589 set_option_value((char_u *)"bh", 0L, | |
590 (char_u *)"wipe", OPT_LOCAL); | |
591 set_option_value((char_u *)"diff", 0L, | |
1302 | 592 NULL, OPT_LOCAL); |
825 | 593 } |
800 | 594 } |
595 if (res == OK) | |
596 { | |
597 char_u *p, *e; | |
598 linenr_T lnum = 0; | |
599 | |
600 for (p = pum_array[pum_selected].pum_info; *p != NUL; ) | |
601 { | |
602 e = vim_strchr(p, '\n'); | |
603 if (e == NULL) | |
604 { | |
605 ml_append(lnum++, p, 0, FALSE); | |
606 break; | |
607 } | |
608 else | |
609 { | |
610 *e = NUL; | |
835 | 611 ml_append(lnum++, p, (int)(e - p + 1), FALSE); |
800 | 612 *e = '\n'; |
613 p = e + 1; | |
614 } | |
615 } | |
616 | |
617 /* Increase the height of the preview window to show the | |
618 * text, but no more than 'previewheight' lines. */ | |
838 | 619 if (repeat == 0) |
800 | 620 { |
838 | 621 if (lnum > p_pvh) |
622 lnum = p_pvh; | |
623 if (curwin->w_height < lnum) | |
624 { | |
625 win_setheight((int)lnum); | |
626 resized = TRUE; | |
627 } | |
800 | 628 } |
629 | |
630 curbuf->b_changed = 0; | |
631 curbuf->b_p_ma = FALSE; | |
2113
85ad19790706
updated for version 7.2.396
Bram Moolenaar <bram@zimbu.org>
parents:
2056
diff
changeset
|
632 curwin->w_cursor.lnum = 1; |
800 | 633 curwin->w_cursor.col = 0; |
634 | |
635 if (curwin != curwin_save && win_valid(curwin_save)) | |
636 { | |
637 /* Return cursor to where we were */ | |
638 validate_cursor(); | |
639 redraw_later(SOME_VALID); | |
640 | |
641 /* When the preview window was resized we need to | |
642 * update the view on the buffer. Only go back to | |
643 * the window when needed, otherwise it will always be | |
644 * redraw. */ | |
645 if (resized) | |
646 { | |
647 win_enter(curwin_save, TRUE); | |
648 update_topline(); | |
649 } | |
650 | |
651 /* Update the screen before drawing the popup menu. | |
652 * Enable updating the status lines. */ | |
653 pum_do_redraw = TRUE; | |
654 update_screen(0); | |
655 pum_do_redraw = FALSE; | |
656 | |
816 | 657 if (!resized && win_valid(curwin_save)) |
800 | 658 win_enter(curwin_save, TRUE); |
659 | |
660 /* May need to update the screen again when there are | |
661 * autocommands involved. */ | |
662 pum_do_redraw = TRUE; | |
663 update_screen(0); | |
664 pum_do_redraw = FALSE; | |
665 } | |
666 } | |
667 } | |
668 } | |
669 #endif | |
670 } | |
671 | |
672 /* Never display more than we have */ | |
673 if (pum_first > pum_size - pum_height) | |
674 pum_first = pum_size - pum_height; | |
675 | |
676 if (!resized) | |
677 pum_redraw(); | |
678 | |
679 return resized; | |
680 } | |
681 | |
682 /* | |
683 * Undisplay the popup menu (later). | |
684 */ | |
685 void | |
686 pum_undisplay() | |
687 { | |
688 pum_array = NULL; | |
689 redraw_all_later(SOME_VALID); | |
940 | 690 #ifdef FEAT_WINDOWS |
691 redraw_tabline = TRUE; | |
692 #endif | |
800 | 693 status_redraw_all(); |
694 } | |
695 | |
696 /* | |
697 * Clear the popup menu. Currently only resets the offset to the first | |
698 * displayed item. | |
699 */ | |
700 void | |
701 pum_clear() | |
702 { | |
703 pum_first = 0; | |
704 } | |
705 | |
706 /* | |
707 * Return TRUE if the popup menu is displayed. | |
708 * Overruled when "pum_do_redraw" is set, used to redraw the status lines. | |
709 */ | |
710 int | |
711 pum_visible() | |
712 { | |
713 return !pum_do_redraw && pum_array != NULL; | |
714 } | |
715 | |
716 /* | |
717 * Return the height of the popup menu, the number of entries visible. | |
718 * Only valid when pum_visible() returns TRUE! | |
719 */ | |
720 int | |
721 pum_get_height() | |
722 { | |
723 return pum_height; | |
724 } | |
725 | |
726 #endif |