diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 03ab2a76ad..058b36b8f4 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1609,14 +1609,16 @@ static void init_prompt(int cmdchar_todo) // prompt is missing, insert it or append a line with it if (*text == NUL) { ml_replace(curbuf->b_prompt_start.mark.lnum, prompt, true); + inserted_bytes(curbuf->b_prompt_start.mark.lnum, 0, 0, prompt_len); } else { - ml_append(curbuf->b_ml.ml_line_count, prompt, 0, false); + const linenr_T lnum = curbuf->b_ml.ml_line_count; + ml_append(lnum, prompt, 0, false); + appended_lines_mark(lnum, 1); curbuf->b_prompt_start.mark.lnum = curbuf->b_ml.ml_line_count; } curbuf->b_prompt_start.mark.col = prompt_len; curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; coladvance(curwin, MAXCOL); - inserted_bytes(curbuf->b_ml.ml_line_count, 0, 0, (colnr_T)prompt_len); } // Insert always starts after the prompt, allow editing text after it. diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 65a1f9ccd3..50dd566489 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -1603,6 +1603,15 @@ describe('API/extmarks', function() eq('invalid', get_extmark_range(marks[3])) eq('invalid', get_extmark_range(marks[4])) eq({ 0, 10, 1, 0 }, get_extmark_range(marks[5])) + + feed('hello') + eq({ 0, 15 }, get_extmark_range(marks[1])) + eq({ 0, 15, 1, 0 }, get_extmark_range(marks[5])) + -- init_prompt uses correct range for inserted_bytes when fixing empty prompt. + fn.setline('.', { '', 'last line' }) + eq({ 'discard > ', 'last line' }, api.nvim_buf_get_lines(0, 0, -1, true)) + eq({ 0, 10 }, get_extmark_range(marks[1])) + eq({ 0, 10, 1, 0 }, get_extmark_range(marks[5])) end) it('can get details', function() diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index e884499a98..e87407f176 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -463,6 +463,14 @@ describe('lua: nvim_buf_attach on_lines', function() { 'test1', 'lines', 1, 12, 0, 1, 1, 16 }, } eq({ 'foo > hello', 'there' }, api.nvim_buf_get_lines(0, 0, -1, true)) + + -- init_prompt uses appended_lines_mark when appending to fix prompt. + api.nvim_buf_set_lines(0, 0, -1, true, { 'hi' }) + eq({ 'hi', 'foo > ' }, api.nvim_buf_get_lines(0, 0, -1, true)) + check_events { + { 'test1', 'lines', 1, 13, 0, 2, 1, 18 }, + { 'test1', 'lines', 1, 14, 1, 1, 2, 0 }, + } end) end) @@ -1652,6 +1660,14 @@ describe('lua: nvim_buf_attach on_bytes', function() { 'test1', 'bytes', 1, 15, 2, 0, 6, 0, 10, 10, 0, 7, 7 }, } eq({ '% ', '% ', 'cool > sup', 'dood' }, api.nvim_buf_get_lines(0, 0, -1, true)) + + -- init_prompt uses appended_lines_mark when appending to fix prompt. + api.nvim_buf_set_lines(0, 0, -1, true, { 'hi' }) + eq({ 'hi', 'cool > ' }, api.nvim_buf_get_lines(0, 0, -1, true)) + check_events { + { 'test1', 'bytes', 1, 16, 0, 0, 0, 4, 0, 22, 1, 0, 3 }, + { 'test1', 'bytes', 1, 17, 1, 0, 3, 0, 0, 0, 1, 0, 8 }, + } end) local function test_lockmarks(mode)