Mercurial > vim
comparison src/popupmnu.c @ 15521:6d949e552e99 v8.1.0768
patch 8.1.0768: updating completions may cause the popup menu to flicker
commit https://github.com/vim/vim/commit/ae654385dfb2ae4c1d70789d1dce3676dba4dfbc
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jan 17 21:09:05 2019 +0100
patch 8.1.0768: updating completions may cause the popup menu to flicker
Problem: Updating completions may cause the popup menu to flicker.
Solution: Avoid updating the text below the popup menu before drawing the
popup menu.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 17 Jan 2019 21:15:06 +0100 |
parents | 55ccc2d353bd |
children | adc6442118b8 |
comparison
equal
deleted
inserted
replaced
15520:f356d2eb8202 | 15521:6d949e552e99 |
---|---|
17 static pumitem_T *pum_array = NULL; /* items of displayed pum */ | 17 static pumitem_T *pum_array = NULL; /* items of displayed pum */ |
18 static int pum_size; /* nr of items in "pum_array" */ | 18 static int pum_size; /* nr of items in "pum_array" */ |
19 static int pum_selected; /* index of selected item or -1 */ | 19 static int pum_selected; /* index of selected item or -1 */ |
20 static int pum_first = 0; /* index of top item */ | 20 static int pum_first = 0; /* index of top item */ |
21 | 21 |
22 static int call_update_screen = FALSE; | |
23 | |
22 static int pum_height; /* nr of displayed pum items */ | 24 static int pum_height; /* nr of displayed pum items */ |
23 static int pum_width; /* width of displayed pum items */ | 25 static int pum_width; /* width of displayed pum items */ |
24 static int pum_base_width; /* width of pum items base */ | 26 static int pum_base_width; /* width of pum items base */ |
25 static int pum_kind_width; /* width of pum items kind column */ | 27 static int pum_kind_width; /* width of pum items kind column */ |
26 static int pum_extra_width; /* width of extra stuff */ | 28 static int pum_extra_width; /* width of extra stuff */ |
34 static int pum_win_height; | 36 static int pum_win_height; |
35 static int pum_win_col; | 37 static int pum_win_col; |
36 static int pum_win_wcol; | 38 static int pum_win_wcol; |
37 static int pum_win_width; | 39 static int pum_win_width; |
38 | 40 |
39 static int pum_do_redraw = FALSE; /* do redraw anyway */ | 41 static int pum_do_redraw = FALSE; // do redraw anyway |
42 static int pum_skip_redraw = FALSE; // skip redraw | |
40 | 43 |
41 static int pum_set_selected(int n, int repeat); | 44 static int pum_set_selected(int n, int repeat); |
42 | 45 |
43 #define PUM_DEF_HEIGHT 10 | 46 #define PUM_DEF_HEIGHT 10 |
44 | 47 |
349 | 352 |
350 /* Set selected item and redraw. If the window size changed need to | 353 /* Set selected item and redraw. If the window size changed need to |
351 * redo the positioning. Limit this to two times, when there is not | 354 * redo the positioning. Limit this to two times, when there is not |
352 * much room the window size will keep changing. */ | 355 * much room the window size will keep changing. */ |
353 } while (pum_set_selected(selected, redo_count) && ++redo_count <= 2); | 356 } while (pum_set_selected(selected, redo_count) && ++redo_count <= 2); |
357 } | |
358 | |
359 /* | |
360 * Set a flag that when pum_redraw() is called it first calls update_screen(). | |
361 * This will avoid clearing and redrawing the popup menu, prevent flicker. | |
362 */ | |
363 void | |
364 pum_call_update_screen() | |
365 { | |
366 call_update_screen = TRUE; | |
367 | |
368 // Update the cursor position to be able to compute the popup menu | |
369 // position. The cursor line length may have changed because of the | |
370 // inserted completion. | |
371 curwin->w_valid &= VALID_CROW|VALID_CHEIGHT; | |
372 validate_cursor(); | |
373 } | |
374 | |
375 /* | |
376 * Return TRUE if we are going to redraw the popup menu and the screen position | |
377 * "row"/"col" is under the popup menu. | |
378 */ | |
379 int | |
380 pum_under_menu(int row, int col) | |
381 { | |
382 return pum_skip_redraw | |
383 && row >= pum_row | |
384 && row < pum_row + pum_height | |
385 && col >= pum_col - 1 | |
386 && col < pum_col + pum_width; | |
354 } | 387 } |
355 | 388 |
356 /* | 389 /* |
357 * Redraw the popup menu, using "pum_first" and "pum_selected". | 390 * Redraw the popup menu, using "pum_first" and "pum_selected". |
358 */ | 391 */ |
374 int thumb_pos = 0; | 407 int thumb_pos = 0; |
375 int thumb_heigth = 1; | 408 int thumb_heigth = 1; |
376 int round; | 409 int round; |
377 int n; | 410 int n; |
378 | 411 |
379 /* Never display more than we have */ | 412 if (call_update_screen) |
413 { | |
414 call_update_screen = FALSE; | |
415 pum_skip_redraw = TRUE; // do not redraw in pum_may_redraw(). | |
416 update_screen(0); | |
417 pum_skip_redraw = FALSE; | |
418 } | |
419 | |
420 // never display more than we have | |
380 if (pum_first > pum_size - pum_height) | 421 if (pum_first > pum_size - pum_height) |
381 pum_first = pum_size - pum_height; | 422 pum_first = pum_size - pum_height; |
382 | 423 |
383 if (pum_scrollbar) | 424 if (pum_scrollbar) |
384 { | 425 { |
787 /* May need to update the screen again when there are | 828 /* May need to update the screen again when there are |
788 * autocommands involved. */ | 829 * autocommands involved. */ |
789 pum_do_redraw = TRUE; | 830 pum_do_redraw = TRUE; |
790 update_screen(0); | 831 update_screen(0); |
791 pum_do_redraw = FALSE; | 832 pum_do_redraw = FALSE; |
833 call_update_screen = FALSE; | |
792 } | 834 } |
793 } | 835 } |
794 } | 836 } |
795 } | 837 } |
796 #endif | 838 #endif |
842 { | 884 { |
843 pumitem_T *array = pum_array; | 885 pumitem_T *array = pum_array; |
844 int len = pum_size; | 886 int len = pum_size; |
845 int selected = pum_selected; | 887 int selected = pum_selected; |
846 | 888 |
847 if (!pum_visible()) | 889 if (!pum_visible() || pum_skip_redraw) |
848 return; // nothing to do | 890 return; // nothing to do |
849 | 891 |
850 if (pum_window != curwin | 892 if (pum_window != curwin |
851 || (pum_win_row == curwin->w_wrow + W_WINROW(curwin) | 893 || (pum_win_row == curwin->w_wrow + W_WINROW(curwin) |
852 && pum_win_height == curwin->w_height | 894 && pum_win_height == curwin->w_height |