diff --git a/src/insexpand.c b/src/insexpand.c index 286fc0b472..c231aa41b8 100644 --- a/src/insexpand.c +++ b/src/insexpand.c @@ -5104,7 +5104,7 @@ get_next_default_completion(ins_compl_next_state_T *st, pos_T *start_pos) ptr = ins_compl_get_next_word_or_line(st->ins_buf, st->cur_match_pos, &len, &cont_s_ipos); if (ptr == NULL || (ins_compl_has_preinsert() - && STRCMP(ptr, compl_pattern.string) == 0)) + && STRCMP(ptr, ins_compl_leader()) == 0)) continue; if (is_nearest_active() && in_curbuf) @@ -6222,6 +6222,7 @@ ins_compl_next( || (compl_autocomplete && !ins_compl_has_preinsert()); int compl_fuzzy_match = (cur_cot_flags & COT_FUZZY) != 0; int compl_preinsert = ins_compl_has_preinsert(); + int has_autocomplete_delay = (compl_autocomplete && p_acl > 0); // When user complete function return -1 for findstart which is next // time of 'always', compl_shown_match become NULL. @@ -6265,7 +6266,11 @@ ins_compl_next( // Insert the text of the new completion, or the compl_leader. if (!started && ins_compl_preinsert_longest()) + { ins_compl_insert(TRUE, TRUE); + if (has_autocomplete_delay) + update_screen(0); // Show the inserted text right away + } else if (compl_no_insert && !started && !compl_preinsert) { ins_compl_insert_bytes(compl_orig_text.string + get_compl_len(), -1); @@ -6291,7 +6296,7 @@ ins_compl_next( // may undisplay the popup menu first ins_compl_upd_pum(); - if (pum_enough_matches()) + if (pum_enough_matches() && !has_autocomplete_delay) // Will display the popup menu, don't redraw yet to avoid flicker. pum_call_update_screen(); else @@ -6299,16 +6304,19 @@ ins_compl_next( // inserted. update_screen(0); - // display the updated popup menu - ins_compl_show_pum(); -#ifdef FEAT_GUI - if (gui.in_use) + if (!has_autocomplete_delay) { - // Show the cursor after the match, not after the redrawn text. - setcursor(); - out_flush_cursor(FALSE, FALSE); - } + // display the updated popup menu + ins_compl_show_pum(); +#ifdef FEAT_GUI + if (gui.in_use) + { + // Show the cursor after the match, not after the redrawn text. + setcursor(); + out_flush_cursor(FALSE, FALSE); + } #endif + } // Delete old text to be replaced, since we're still searching and // don't want to match ourselves! @@ -7362,6 +7370,12 @@ ins_complete(int c, int enable_pum) { if (char_avail()) { + if (ins_compl_preinsert_effect() + && ins_compl_win_active(curwin)) + { + ins_compl_delete(); // Remove pre-inserted text + compl_ins_end_col = compl_col; + } ins_compl_restart(); compl_interrupted = TRUE; break; diff --git a/src/testdir/dumps/Test_autocompletedelay_longest_1.dump b/src/testdir/dumps/Test_autocompletedelay_longest_1.dump new file mode 100644 index 0000000000..10a50793cc --- /dev/null +++ b/src/testdir/dumps/Test_autocompletedelay_longest_1.dump @@ -0,0 +1,10 @@ +|a+0&#ffffff0|u|t|o|c|o|m|p|l|e|t|e| @62 +|a|u|t|o|c|o|m|x@2| @64 +|a|u|t|o|c>o+0#00e0003&|m| +0#0000000&@67 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|1| @10|T|o|p| diff --git a/src/testdir/dumps/Test_autocompletedelay_longest_2.dump b/src/testdir/dumps/Test_autocompletedelay_longest_2.dump new file mode 100644 index 0000000000..19a83bfa78 --- /dev/null +++ b/src/testdir/dumps/Test_autocompletedelay_longest_2.dump @@ -0,0 +1,10 @@ +|a+0&#ffffff0|u|t|o|c|o|m|p|l|e|t|e| @62 +|a|u|t|o|c|o|m|x@2| @64 +|a|u|t|o|c>o+0#00e0003&|m| +0#0000000&@67 +|a+0#0000001#ffd7ff255|u|t|o|c|o|m|x@2| @4| +0#4040ff13#ffffff0@59 +|a+0#0000001#ffd7ff255|u|t|o|c|o|m|p|l|e|t|e| @2| +0#4040ff13#ffffff0@59 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|1| @10|T|o|p| diff --git a/src/testdir/dumps/Test_autocompletedelay_longest_3.dump b/src/testdir/dumps/Test_autocompletedelay_longest_3.dump new file mode 100644 index 0000000000..52bda2c30c --- /dev/null +++ b/src/testdir/dumps/Test_autocompletedelay_longest_3.dump @@ -0,0 +1,10 @@ +|a+0&#ffffff0|u|t|o|c|o|m|p|l|e|t|e| @62 +|a|u|t|o|c|o|m|x@2| @64 +|a|u>t+0#00e0003&|o|c|o|m| +0#0000000&@67 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|1| @10|A|l@1| diff --git a/src/testdir/dumps/Test_autocompletedelay_longest_4.dump b/src/testdir/dumps/Test_autocompletedelay_longest_4.dump new file mode 100644 index 0000000000..09a8514da0 --- /dev/null +++ b/src/testdir/dumps/Test_autocompletedelay_longest_4.dump @@ -0,0 +1,10 @@ +|a+0&#ffffff0|u|t|o|c|o|m|p|l|e|t|e| @62 +|a|u|t|o|c|o|m|x@2| @64 +|a|u>t+0#00e0003&|o|c|o|m| +0#0000000&@67 +|a+0#0000001#ffd7ff255|u|t|o|c|o|m|x@2| @4| +0#4040ff13#ffffff0@59 +|a+0#0000001#ffd7ff255|u|t|o|c|o|m|p|l|e|t|e| @2| +0#4040ff13#ffffff0@59 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|1| @10|A|l@1| diff --git a/src/testdir/dumps/Test_autocompletedelay_preinsert_1.dump b/src/testdir/dumps/Test_autocompletedelay_preinsert_1.dump new file mode 100644 index 0000000000..3b1bc4bbd5 --- /dev/null +++ b/src/testdir/dumps/Test_autocompletedelay_preinsert_1.dump @@ -0,0 +1,10 @@ +|a+0&#ffffff0|u|t|o|c|o|m|p|l|e|t|e| @62 +|a|u|t|o|c|o|m|x@2| @64 +|a|u>t+0#00e0003&|o|c|o|m|p|l|e|t|e| +0#0000000&@62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|1| @10|A|l@1| diff --git a/src/testdir/dumps/Test_autocompletedelay_preinsert_2.dump b/src/testdir/dumps/Test_autocompletedelay_preinsert_2.dump new file mode 100644 index 0000000000..17252dfa3e --- /dev/null +++ b/src/testdir/dumps/Test_autocompletedelay_preinsert_2.dump @@ -0,0 +1,10 @@ +|a+0&#ffffff0|u|t|o|c|o|m|p|l|e|t|e| @62 +|a|u|t|o|c|o|m|x@2| @64 +|a|u>t+0#00e0003&|o|c|o|m|p|l|e|t|e| +0#0000000&@62 +|a+0#0000001#e0e0e08|u|t|o|c|o|m|p|l|e|t|e| @2| +0#4040ff13#ffffff0@59 +|a+0#0000001#ffd7ff255|u|t|o|c|o|m|x@2| @4| +0#4040ff13#ffffff0@59 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|1| @10|A|l@1| diff --git a/src/testdir/test_ins_complete.vim b/src/testdir/test_ins_complete.vim index e7346b8b58..b10e07433a 100644 --- a/src/testdir/test_ins_complete.vim +++ b/src/testdir/test_ins_complete.vim @@ -5756,7 +5756,7 @@ func Test_autocomplete_longest() call test_override("char_avail", 1) new inoremap =GetLine() - set completeopt=longest autocomplete + set completeopt+=longest autocomplete call setline(1, ["foobar", "foozbar"]) call feedkeys("Go\", 'tx') @@ -5996,4 +5996,45 @@ func Test_refresh_always_with_fuzzy() call test_override("char_avail", 0) endfunc +func Test_autocompletedelay_longest_preinsert() + CheckScreendump + let lines =<< trim [SCRIPT] + call setline(1, ['autocomplete', 'autocomxxx']) + set autocomplete completeopt+=longest autocompletedelay=500 + [SCRIPT] + call writefile(lines, 'XTest_autocompletedelay', 'D') + let buf = RunVimInTerminal('-S XTest_autocompletedelay', {'rows': 10}) + + " No spurious characters when autocompletedelay is in effect + call term_sendkeys(buf, "Goau") + sleep 10m + call term_sendkeys(buf, "toc") + sleep 100m + call VerifyScreenDump(buf, 'Test_autocompletedelay_longest_1', {}) + sleep 500m + call VerifyScreenDump(buf, 'Test_autocompletedelay_longest_2', {}) + + " Deleting a char should still show longest text + call term_sendkeys(buf, "\Saut") + sleep 10m + call term_sendkeys(buf, "\") + sleep 100m + call VerifyScreenDump(buf, 'Test_autocompletedelay_longest_3', {}) + sleep 500m + call VerifyScreenDump(buf, 'Test_autocompletedelay_longest_4', {}) + + " Preinsert + call term_sendkeys(buf, "\:set completeopt& completeopt+=preinsert\") + + " Show preinserted text right away but display popup later + call term_sendkeys(buf, "\Sau") + sleep 100m + call VerifyScreenDump(buf, 'Test_autocompletedelay_preinsert_1', {}) + sleep 500m + call VerifyScreenDump(buf, 'Test_autocompletedelay_preinsert_2', {}) + + call term_sendkeys(buf, "\") + call StopVimInTerminal(buf) +endfunc + " vim: shiftwidth=2 sts=2 expandtab nofoldenable diff --git a/src/version.c b/src/version.c index 431536543a..773c66b1b6 100644 --- a/src/version.c +++ b/src/version.c @@ -729,6 +729,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1820, /**/ 1819, /**/