diff --git a/src/nvim/eval/buffer.c b/src/nvim/eval/buffer.c index 80202a8cec..dd731d0d26 100644 --- a/src/nvim/eval/buffer.c +++ b/src/nvim/eval/buffer.c @@ -801,10 +801,9 @@ void f_prompt_setprompt(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } if (curwin->w_buffer == buf && curwin->w_cursor.lnum == prompt_lno) { - coladvance(curwin, cursor_col); + curwin->w_cursor.col = cursor_col; } - changed_lines_redraw_buf(buf, prompt_lno, prompt_lno + 1, 0); - redraw_buf_later(buf, UPD_INVERTED); + changed_lines(buf, prompt_lno, 0, prompt_lno + 1, 0, true); } // Clear old prompt text and replace with the new one diff --git a/test/functional/legacy/prompt_buffer_spec.lua b/test/functional/legacy/prompt_buffer_spec.lua index 550853d06b..36535245ea 100644 --- a/test/functional/legacy/prompt_buffer_spec.lua +++ b/test/functional/legacy/prompt_buffer_spec.lua @@ -62,7 +62,7 @@ describe('prompt buffer', function() screen:expect([[ cmd: ^ | {1:~ }|*3 - {3:[Prompt] }| + {3:[Prompt] [+] }| other buffer | {1:~ }|*3 {5:-- INSERT --} | @@ -149,7 +149,7 @@ describe('prompt buffer', function() screen:expect([[ cmd: | {1:~ }|*3 - {2:[Prompt] }| + {2:[Prompt] [+] }| ^other buffer | {1:~ }|*3 | @@ -158,7 +158,7 @@ describe('prompt buffer', function() screen:expect([[ cmd: ^ | {1:~ }|*3 - {3:[Prompt] }| + {3:[Prompt] [+] }| other buffer | {1:~ }|*3 {5:-- INSERT --} | @@ -167,7 +167,7 @@ describe('prompt buffer', function() screen:expect([[ cmd:^ | {1:~ }|*3 - {3:[Prompt] }| + {3:[Prompt] [+] }| other buffer | {1:~ }|*3 | @@ -892,10 +892,42 @@ describe('prompt buffer', function() {1:~ }|*7 | ]]) + -- Correct col when prompt has multi-cell chars. + feed('i') + screen:expect([[ + new-prompt > user input | + <>< user inp^ut | + {1:~ }|*7 + {5:-- INSERT --} | + ]]) + set_prompt('\t > ') + screen:expect([[ + new-prompt > user input | + > user inp^ut | + {1:~ }|*7 + {5:-- INSERT --} | + ]]) + -- Works with 'virtualedit': coladd remains sensible. Cursor is redrawn correctly. + -- Tab size visually changes due to multiples of 'tabstop'. + command('set virtualedit=all') + feed('Sab3h') + screen:expect([[ + new-prompt > user input | + > a ^ b | + {1:~ }|*7 + {5:-- INSERT --} | + ]]) + set_prompt('😊 > ') + screen:expect([[ + new-prompt > user input | + 😊 > a ^ b | + {1:~ }|*7 + {5:-- INSERT --} | + ]]) -- No crash when setting shorter prompt than curbuf's in other buffer. - feed('izt') - command('new | setlocal buftype=prompt') + feed('zt') + command('set virtualedit& | new | setlocal buftype=prompt') set_prompt('looooooooooooooooooooooooooooooooooooooooooooong > ', '') -- curbuf set_prompt('foo > ') screen:expect([[ @@ -904,7 +936,7 @@ describe('prompt buffer', function() ^ | {1:~ }| {3:[Prompt] [+] }| - foo > user input | + foo > a b | {1:~ }|*3 {5:-- INSERT --} | ]]) diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index dfca9f02f6..6c142cd01e 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -422,6 +422,48 @@ describe('lua: nvim_buf_attach on_lines', function() feed('I ') eq({ api.nvim_get_current_buf(), 0, 1, 1 }, exec_lua('return _G.res')) end) + + it('prompt buffer', function() + local check_events = setup_eventcheck(false, nil, {}) + api.nvim_set_option_value('buftype', 'prompt', {}) + feed('i') + check_events { + { 'test1', 'lines', 1, 4, 0, 1, 1, 1 }, + } + fn.prompt_setprompt('', 'foo > ') + check_events { + { 'test1', 'lines', 1, 5, 0, 1, 1, 3 }, + } + feed('hello') + check_events { + { 'test1', 'lines', 1, 6, 0, 1, 1, 7 }, + } + fn.prompt_setprompt('', 'super-foo > ') + check_events { + { 'test1', 'lines', 1, 7, 0, 1, 1, 12 }, + } + eq({ 'super-foo > hello' }, api.nvim_buf_get_lines(0, 0, -1, true)) + -- Do this in the same event. + exec_lua(function() + vim.fn.setpos("':", { 0, 1, 999, 0 }) + vim.fn.prompt_setprompt('', 'discard > ') + end) + check_events { + { 'test1', 'lines', 1, 8, 0, 1, 1, 18 }, + } + eq({ 'discard > ' }, api.nvim_buf_get_lines(0, 0, -1, true)) + feed('hellothere') + check_events { + { 'test1', 'lines', 1, 9, 0, 1, 1, 11 }, + { 'test1', 'lines', 1, 10, 0, 1, 2, 16 }, + { 'test1', 'lines', 1, 11, 1, 2, 2, 1 }, + } + fn.prompt_setprompt('', 'foo > ') + check_events { + { 'test1', 'lines', 1, 12, 0, 1, 1, 16 }, + } + eq({ 'foo > hello', 'there' }, api.nvim_buf_get_lines(0, 0, -1, true)) + end) end) describe('lua: nvim_buf_attach on_bytes', function()