diff --git a/src/edit.c b/src/edit.c index 2283ff2af5..3866abbb8c 100644 --- a/src/edit.c +++ b/src/edit.c @@ -2808,9 +2808,6 @@ set_completion(colnr_T startcol, list_T *list) ins_compl_prep(' '); ins_compl_clear(); - if (stop_arrow() == FAIL) - return; - compl_direction = FORWARD; if (startcol > curwin->w_cursor.col) startcol = curwin->w_cursor.col; @@ -3890,7 +3887,8 @@ ins_compl_prep(int c) /* put the cursor on the last char, for 'tw' formatting */ if (prev_col > 0) dec_cursor(); - if (stop_arrow() == OK) + /* only format when something was inserted */ + if (!arrow_used && !ins_need_undo) insertchar(NUL, 0, -1); if (prev_col > 0 && ml_get_curline()[curwin->w_cursor.col] != NUL) diff --git a/src/screen.c b/src/screen.c index ed6cb5fbec..7b2336bc15 100644 --- a/src/screen.c +++ b/src/screen.c @@ -7786,6 +7786,10 @@ next_search_hl( } } +/* + * If there is a match fill "shl" and return one. + * Return zero otherwise. + */ static int next_search_hl_pos( match_T *shl, /* points to a match */ @@ -7794,55 +7798,52 @@ next_search_hl_pos( colnr_T mincol) /* minimal column for a match */ { int i; - int bot = -1; + int found = -1; - shl->lnum = 0; for (i = posmatch->cur; i < MAXPOSMATCH; i++) { llpos_T *pos = &posmatch->pos[i]; if (pos->lnum == 0) break; - if (pos->col + pos->len - 1 <= mincol) + if (pos->len == 0 && pos->col < mincol) continue; if (pos->lnum == lnum) { - if (shl->lnum == lnum) + if (found >= 0) { - /* partially sort positions by column numbers - * on the same line */ - if (pos->col < posmatch->pos[bot].col) + /* if this match comes before the one at "found" then swap + * them */ + if (pos->col < posmatch->pos[found].col) { llpos_T tmp = *pos; - *pos = posmatch->pos[bot]; - posmatch->pos[bot] = tmp; + *pos = posmatch->pos[found]; + posmatch->pos[found] = tmp; } } else - { - bot = i; - shl->lnum = lnum; - } + found = i; } } posmatch->cur = 0; - if (shl->lnum == lnum && bot >= 0) + if (found >= 0) { - colnr_T start = posmatch->pos[bot].col == 0 - ? 0 : posmatch->pos[bot].col - 1; - colnr_T end = posmatch->pos[bot].col == 0 - ? MAXCOL : start + posmatch->pos[bot].len; + colnr_T start = posmatch->pos[found].col == 0 + ? 0 : posmatch->pos[found].col - 1; + colnr_T end = posmatch->pos[found].col == 0 + ? MAXCOL : start + posmatch->pos[found].len; + shl->lnum = lnum; shl->rm.startpos[0].lnum = 0; shl->rm.startpos[0].col = start; shl->rm.endpos[0].lnum = 0; shl->rm.endpos[0].col = end; shl->is_addpos = TRUE; - posmatch->cur = bot + 1; - return TRUE; + posmatch->cur = found + 1; + return 1; } - return FALSE; + return 0; } #endif diff --git a/src/testdir/test_match.vim b/src/testdir/test_match.vim index 3b20d5d439..9398ef2f27 100644 --- a/src/testdir/test_match.vim +++ b/src/testdir/test_match.vim @@ -191,7 +191,15 @@ func Test_matchaddpos() call assert_equal(screenattr(2,2), screenattr(1,7)) call assert_notequal(screenattr(2,2), screenattr(1,8)) + call clearmatches() + call matchaddpos('Error', [[1], [2,2]]) + redraw! + call assert_equal(screenattr(2,2), screenattr(1,1)) + call assert_equal(screenattr(2,2), screenattr(1,10)) + call assert_notequal(screenattr(2,2), screenattr(1,11)) + nohl + call clearmatches() syntax off set hlsearch& endfunc diff --git a/src/testdir/test_popup.vim b/src/testdir/test_popup.vim index 7cb0e10aa1..38459b323e 100644 --- a/src/testdir/test_popup.vim +++ b/src/testdir/test_popup.vim @@ -378,7 +378,7 @@ func DummyCompleteFour(findstart, base) endif endfunc -:"Test that 'completefunc' works when it's OK. +" Test that 'completefunc' works when it's OK. func Test_omnifunc_with_check() new setlocal omnifunc=DummyCompleteFour @@ -400,4 +400,30 @@ func Test_omnifunc_with_check() q! endfunc +function UndoComplete() + call complete(1, ['January', 'February', 'March', + \ 'April', 'May', 'June', 'July', 'August', 'September', + \ 'October', 'November', 'December']) + return '' +endfunc + +" Test that no undo item is created when no completion is inserted +func Test_complete_no_undo() + set completeopt=menu,preview,noinsert,noselect + inoremap =UndoComplete() + new + call feedkeys("ixxx\\yyy\k", 'xt') + call feedkeys("iaaa\0", 'xt') + call assert_equal('aaa', getline(2)) + call feedkeys("i\\", 'xt') + call assert_equal('aaa', getline(2)) + call feedkeys("u", 'xt') + call assert_equal('', getline(2)) + + iunmap + set completeopt& + q! +endfunc + + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c index 20a93d75ee..e15a74670e 100644 --- a/src/version.c +++ b/src/version.c @@ -779,6 +779,10 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 41, +/**/ + 40, /**/ 39, /**/