Mercurial > vim
annotate src/popupmnu.c @ 9980:b222552cf0c4 v7.4.2263
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Aug 26 22:29:11 2016 +0200
patch 7.4.2263
Problem: :filter does not work for many commands. Can only get matching
messages.
Solution: Make :filter work for :command, :map, :list, :number and :print.
Make ":filter!" show non-matching lines.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 26 Aug 2016 22:30:07 +0200 |
parents | ad9edad64d22 |
children | 4aead6a9b7a9 |
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 |
8220
ad9edad64d22
commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
78 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) |
800 | 79 if (firstwin->w_p_pvw) |
80 top_clear = firstwin->w_height; | |
81 else | |
8220
ad9edad64d22
commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
82 #endif |
800 | 83 top_clear = 0; |
84 | |
8220
ad9edad64d22
commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
85 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) |
800 | 86 /* When the preview window is at the bottom stop just above it. Also |
87 * avoid drawing over the status line so that it's clear there is a window | |
88 * boundary. */ | |
89 if (lastwin->w_p_pvw) | |
90 above_row -= lastwin->w_height + lastwin->w_status_height + 1; | |
8220
ad9edad64d22
commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
91 #endif |
800 | 92 |
93 /* | |
94 * Figure out the size and position of the pum. | |
95 */ | |
96 if (size < PUM_DEF_HEIGHT) | |
97 pum_height = size; | |
98 else | |
99 pum_height = PUM_DEF_HEIGHT; | |
100 if (p_ph > 0 && pum_height > p_ph) | |
101 pum_height = p_ph; | |
102 | |
103 /* Put the pum below "row" if possible. If there are few lines decide on | |
104 * where there is more room. */ | |
1622 | 105 if (row + 2 >= above_row - pum_height |
106 && row > (above_row - top_clear) / 2) | |
800 | 107 { |
108 /* pum above "row" */ | |
1622 | 109 |
110 /* Leave two lines of context if possible */ | |
111 if (curwin->w_wrow - curwin->w_cline_row >= 2) | |
112 context_lines = 2; | |
113 else | |
114 context_lines = curwin->w_wrow - curwin->w_cline_row; | |
115 | |
116 if (row >= size + context_lines) | |
800 | 117 { |
1622 | 118 pum_row = row - size - context_lines; |
800 | 119 pum_height = size; |
120 } | |
121 else | |
122 { | |
123 pum_row = 0; | |
1622 | 124 pum_height = row - context_lines; |
800 | 125 } |
126 if (p_ph > 0 && pum_height > p_ph) | |
127 { | |
128 pum_row += pum_height - p_ph; | |
129 pum_height = p_ph; | |
130 } | |
131 } | |
132 else | |
133 { | |
134 /* pum below "row" */ | |
1622 | 135 |
136 /* Leave two lines of context if possible */ | |
137 if (curwin->w_cline_row + curwin->w_cline_height - curwin->w_wrow >= 3) | |
138 context_lines = 3; | |
139 else | |
140 context_lines = curwin->w_cline_row | |
141 + curwin->w_cline_height - curwin->w_wrow; | |
142 | |
143 pum_row = row + context_lines; | |
800 | 144 if (size > above_row - pum_row) |
145 pum_height = above_row - pum_row; | |
146 else | |
147 pum_height = size; | |
148 if (p_ph > 0 && pum_height > p_ph) | |
149 pum_height = p_ph; | |
150 } | |
151 | |
152 /* don't display when we only have room for one line */ | |
153 if (pum_height < 1 || (pum_height == 1 && size > 1)) | |
154 return; | |
155 | |
8220
ad9edad64d22
commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
156 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) |
800 | 157 /* If there is a preview window at the top avoid drawing over it. */ |
158 if (firstwin->w_p_pvw | |
159 && pum_row < firstwin->w_height | |
160 && pum_height > firstwin->w_height + 4) | |
161 { | |
162 pum_row += firstwin->w_height; | |
163 pum_height -= firstwin->w_height; | |
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 { | |
585 if (curbuf->b_fname == NULL | |
586 && curbuf->b_p_bt[0] == 'n' && curbuf->b_p_bt[2] == 'f' | |
587 && curbuf->b_p_bh[0] == 'w') | |
588 { | |
589 /* Already a "wipeout" buffer, make it empty. */ | |
590 while (!bufempty()) | |
591 ml_delete((linenr_T)1, FALSE); | |
592 } | |
825 | 593 else |
800 | 594 { |
825 | 595 /* Don't want to sync undo in the current buffer. */ |
596 ++no_u_sync; | |
1743 | 597 res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0, NULL); |
825 | 598 --no_u_sync; |
599 if (res == OK) | |
600 { | |
601 /* Edit a new, empty buffer. Set options for a "wipeout" | |
602 * buffer. */ | |
603 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL); | |
604 set_option_value((char_u *)"bt", 0L, | |
605 (char_u *)"nofile", OPT_LOCAL); | |
606 set_option_value((char_u *)"bh", 0L, | |
607 (char_u *)"wipe", OPT_LOCAL); | |
608 set_option_value((char_u *)"diff", 0L, | |
1302 | 609 NULL, OPT_LOCAL); |
825 | 610 } |
800 | 611 } |
612 if (res == OK) | |
613 { | |
614 char_u *p, *e; | |
615 linenr_T lnum = 0; | |
616 | |
617 for (p = pum_array[pum_selected].pum_info; *p != NUL; ) | |
618 { | |
619 e = vim_strchr(p, '\n'); | |
620 if (e == NULL) | |
621 { | |
622 ml_append(lnum++, p, 0, FALSE); | |
623 break; | |
624 } | |
625 else | |
626 { | |
627 *e = NUL; | |
835 | 628 ml_append(lnum++, p, (int)(e - p + 1), FALSE); |
800 | 629 *e = '\n'; |
630 p = e + 1; | |
631 } | |
632 } | |
633 | |
634 /* Increase the height of the preview window to show the | |
635 * text, but no more than 'previewheight' lines. */ | |
838 | 636 if (repeat == 0) |
800 | 637 { |
838 | 638 if (lnum > p_pvh) |
639 lnum = p_pvh; | |
640 if (curwin->w_height < lnum) | |
641 { | |
642 win_setheight((int)lnum); | |
643 resized = TRUE; | |
644 } | |
800 | 645 } |
646 | |
647 curbuf->b_changed = 0; | |
648 curbuf->b_p_ma = FALSE; | |
2113
85ad19790706
updated for version 7.2.396
Bram Moolenaar <bram@zimbu.org>
parents:
2056
diff
changeset
|
649 curwin->w_cursor.lnum = 1; |
800 | 650 curwin->w_cursor.col = 0; |
651 | |
652 if (curwin != curwin_save && win_valid(curwin_save)) | |
653 { | |
6089 | 654 /* When the first completion is done and the preview |
655 * window is not resized, skip the preview window's | |
656 * status line redrawing. */ | |
657 if (ins_compl_active() && !resized) | |
658 curwin->w_redr_status = FALSE; | |
659 | |
800 | 660 /* Return cursor to where we were */ |
661 validate_cursor(); | |
662 redraw_later(SOME_VALID); | |
663 | |
664 /* When the preview window was resized we need to | |
665 * update the view on the buffer. Only go back to | |
666 * the window when needed, otherwise it will always be | |
667 * redraw. */ | |
668 if (resized) | |
669 { | |
7181
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
670 ++no_u_sync; |
800 | 671 win_enter(curwin_save, TRUE); |
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 update_topline(); |
674 } | |
675 | |
676 /* Update the screen before drawing the popup menu. | |
677 * Enable updating the status lines. */ | |
678 pum_do_redraw = TRUE; | |
679 update_screen(0); | |
680 pum_do_redraw = FALSE; | |
681 | |
816 | 682 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
|
683 { |
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
684 ++no_u_sync; |
800 | 685 win_enter(curwin_save, TRUE); |
7181
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
686 --no_u_sync; |
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
687 } |
800 | 688 |
689 /* May need to update the screen again when there are | |
690 * autocommands involved. */ | |
691 pum_do_redraw = TRUE; | |
692 update_screen(0); | |
693 pum_do_redraw = FALSE; | |
694 } | |
695 } | |
696 } | |
697 } | |
698 #endif | |
699 } | |
700 | |
701 if (!resized) | |
702 pum_redraw(); | |
703 | |
704 return resized; | |
705 } | |
706 | |
707 /* | |
708 * Undisplay the popup menu (later). | |
709 */ | |
710 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
711 pum_undisplay(void) |
800 | 712 { |
713 pum_array = NULL; | |
714 redraw_all_later(SOME_VALID); | |
940 | 715 #ifdef FEAT_WINDOWS |
716 redraw_tabline = TRUE; | |
717 #endif | |
800 | 718 status_redraw_all(); |
719 } | |
720 | |
721 /* | |
722 * Clear the popup menu. Currently only resets the offset to the first | |
723 * displayed item. | |
724 */ | |
725 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
726 pum_clear(void) |
800 | 727 { |
728 pum_first = 0; | |
729 } | |
730 | |
731 /* | |
732 * Return TRUE if the popup menu is displayed. | |
733 * Overruled when "pum_do_redraw" is set, used to redraw the status lines. | |
734 */ | |
735 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
736 pum_visible(void) |
800 | 737 { |
738 return !pum_do_redraw && pum_array != NULL; | |
739 } | |
740 | |
741 /* | |
742 * Return the height of the popup menu, the number of entries visible. | |
743 * Only valid when pum_visible() returns TRUE! | |
744 */ | |
745 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
746 pum_get_height(void) |
800 | 747 { |
748 return pum_height; | |
749 } | |
750 | |
751 #endif |