completion: Avoid flicker.

This commit is contained in:
Shougo Matsushita
2016-01-18 12:23:18 +09:00
committed by Justin M. Keyes
parent d4778104b5
commit d92db14241

View File

@@ -184,6 +184,9 @@ static expand_T compl_xp;
static int compl_opt_refresh_always = FALSE; static int compl_opt_refresh_always = FALSE;
static bool compl_show_pum = true; // true: show popup menu
// false: don't show popup menu
typedef struct insert_state { typedef struct insert_state {
VimState state; VimState state;
cmdarg_T *ca; cmdarg_T *ca;
@@ -2321,9 +2324,10 @@ static int ins_compl_make_cyclic(void)
*/ */
void set_completion(colnr_T startcol, list_T *list) void set_completion(colnr_T startcol, list_T *list)
{ {
/* If already doing completions stop it. */ // If already doing completions stop it.
if (ctrl_x_mode != 0) if (ctrl_x_mode != 0) {
ins_compl_prep(' '); ins_compl_prep(' ');
}
ins_compl_clear(); ins_compl_clear();
if (stop_arrow() == FAIL) if (stop_arrow() == FAIL)
@@ -2349,8 +2353,10 @@ void set_completion(colnr_T startcol, list_T *list)
compl_started = TRUE; compl_started = TRUE;
compl_used_match = TRUE; compl_used_match = TRUE;
compl_cont_status = 0; compl_cont_status = 0;
int save_w_wrow = curwin->w_wrow;
compl_curr_match = compl_first_match; compl_curr_match = compl_first_match;
compl_show_pum = false;
if (compl_no_insert) { if (compl_no_insert) {
ins_complete(K_DOWN); ins_complete(K_DOWN);
} else { } else {
@@ -2359,6 +2365,13 @@ void set_completion(colnr_T startcol, list_T *list)
ins_complete(Ctrl_P); ins_complete(Ctrl_P);
} }
} }
// Lazily show the popup menu, unless we got interrupted.
compl_show_pum = true;
if (!compl_interrupted) {
show_pum(save_w_wrow);
}
ui_flush(); ui_flush();
} }
@@ -4781,20 +4794,9 @@ static int ins_complete(int c)
} }
} }
/* Show the popup menu, unless we got interrupted. */ // Show the popup menu, unless we got interrupted.
if (!compl_interrupted) { if (!compl_interrupted && compl_show_pum) {
/* RedrawingDisabled may be set when invoked through complete(). */ show_pum(save_w_wrow);
n = RedrawingDisabled;
RedrawingDisabled = 0;
/* If the cursor moved we need to remove the pum first. */
setcursor();
if (save_w_wrow != curwin->w_wrow)
ins_compl_del_pum();
ins_compl_show_pum();
setcursor();
RedrawingDisabled = n;
} }
compl_was_interrupted = compl_interrupted; compl_was_interrupted = compl_interrupted;
compl_interrupted = FALSE; compl_interrupted = FALSE;
@@ -8522,3 +8524,20 @@ static char_u *do_insert_char_pre(int c)
return res; return res;
} }
static void show_pum(int save_w_wrow)
{
// RedrawingDisabled may be set when invoked through complete().
int n = RedrawingDisabled;
RedrawingDisabled = 0;
// If the cursor moved we need to remove the pum first.
setcursor();
if (save_w_wrow != curwin->w_wrow) {
ins_compl_del_pum();
}
ins_compl_show_pum();
setcursor();
RedrawingDisabled = n;
}