diff --git a/src/nvim/edit.c b/src/nvim/edit.c index a0ae1a3e6b..f4623615b9 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2350,9 +2350,6 @@ void set_completion(colnr_T startcol, list_T *list) } ins_compl_clear(); - if (stop_arrow() == FAIL) - return; - compl_direction = FORWARD; if (startcol > curwin->w_cursor.col) startcol = curwin->w_cursor.col; @@ -3263,14 +3260,19 @@ static bool ins_compl_prep(int c) } else { int prev_col = curwin->w_cursor.col; - /* put the cursor on the last char, for 'tw' formatting */ - if (prev_col > 0) + // put the cursor on the last char, for 'tw' formatting + if (prev_col > 0) { dec_cursor(); - if (stop_arrow() == OK) + } + + if (!arrow_used && !ins_need_undo) { insertchar(NUL, 0, -1); + } + if (prev_col > 0 - && get_cursor_line_ptr()[curwin->w_cursor.col] != NUL) + && get_cursor_line_ptr()[curwin->w_cursor.col] != NUL) { inc_cursor(); + } } // If the popup menu is displayed pressing CTRL-Y means accepting diff --git a/test/functional/viml/completion_spec.lua b/test/functional/viml/completion_spec.lua index 0897c2d836..da3400fb27 100644 --- a/test/functional/viml/completion_spec.lua +++ b/test/functional/viml/completion_spec.lua @@ -317,6 +317,62 @@ describe('completion', function() end) end) + describe('completeopt+=noinsert does not add blank undo items', function() + before_each(function() + source([[ + function! TestComplete() abort + call complete(1, ['foo', 'bar']) + return '' + endfunction + ]]) + execute('set completeopt+=noselect,noinsert') + execute('inoremap =TestComplete()') + end) + + local tests = { + [', , '] = {'', ''}, + [', , '] = {'', ''}, + } + + for name, seq in pairs(tests) do + it('using ' .. name, function() + feed('iaaa') + feed('A' .. seq[1] .. '') + feed('AA') + feed('Abbb') + feed('A' .. seq[2] .. '') + feed('AA') + feed('Accc') + feed('A' .. seq[1] .. '') + feed('AA') + + local expected = { + {'foo', 'bar', 'foo'}, + {'foo', 'bar', 'ccc'}, + {'foo', 'bar'}, + {'foo', 'bbb'}, + {'foo'}, + {'aaa'}, + {''}, + } + + for i = 1, #expected do + if i > 1 then + feed('u') + end + eq(expected[i], eval('getline(1, "$")')) + end + + for i = #expected, 1, -1 do + if i < #expected then + feed('') + end + eq(expected[i], eval('getline(1, "$")')) + end + end) + end + end) + describe("refresh:always", function() before_each(function() source([[