fix(prompt): prompt_setprompt sets cursor col unnecessarily

Problem: prompt_setprompt adjusts the cursor's column number even when it's not
on the prompt's line.

Solution: only adjust when on the prompt's line.
This commit is contained in:
Sean Dewar
2026-02-15 05:45:57 +00:00
parent b3096b5860
commit 2a5d687cc9
2 changed files with 18 additions and 1 deletions

View File

@@ -800,7 +800,7 @@ void f_prompt_setprompt(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
cursor_col += new_prompt_len - old_prompt_len;
}
if (curwin->w_buffer == buf) {
if (curwin->w_buffer == buf && curwin->w_cursor.lnum == prompt_lno) {
coladvance(curwin, cursor_col);
}
changed_lines_redraw_buf(buf, prompt_lno, prompt_lno + 1, 0);

View File

@@ -858,7 +858,24 @@ describe('prompt buffer', function()
]])
eq({ 1, 13 }, api.nvim_buf_get_mark(0, ':'))
-- Cursor not moved when not on the prompt line.
feed('<CR>user input<Esc>k')
screen:expect([[
new-prompt > user inpu^t |
new-prompt > user input |
{1:~ }|*7
|
]])
set_prompt('<>< ')
screen:expect([[
new-prompt > user inpu^t |
<>< user input |
{1:~ }|*7
|
]])
-- No crash when setting shorter prompt than curbuf's in other buffer.
feed('i<C-O>zt')
command('new | setlocal buftype=prompt')
set_prompt('looooooooooooooooooooooooooooooooooooooooooooong > ', '') -- curbuf
set_prompt('foo > ')