fix(prompt): wrong cursor position with cursor keys (#36196)

**Problem**:
Currently, whenever user get's on prompt-text area we move the user to
end of user-input area. As a result when left/c-left,home keys are
triggered at start of user-input the cursor get's placed at end of
user-input. But this behavior can be jarring and unintuitive also it's
different from previous behavior where it'd just stay at start of
input-area. Also, previously when insert-mode was triggered in
prompt-text with n_a for example then cursor was placed at start of
user-input area not at the end. So, that behavior was also broken.

**Solution:**
Restore previous behavior. Don't force user to end of user-input when
entering insert-mode from readonly section.
This commit is contained in:
Shadman
2025-11-08 08:40:37 +06:00
committed by GitHub
parent af5ac171bd
commit 466b2ac192
2 changed files with 37 additions and 12 deletions

View File

@@ -1590,12 +1590,8 @@ static void init_prompt(int cmdchar_todo)
{
char *prompt = prompt_text();
if (curwin->w_cursor.lnum < curbuf->b_prompt_start.mark.lnum
|| (cmdchar_todo != 'O'
&& curwin->w_cursor.lnum == curbuf->b_prompt_start.mark.lnum
&& (curwin->w_cursor.col < (int)strlen(prompt_text())))) {
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
coladvance(curwin, MAXCOL);
if (curwin->w_cursor.lnum < curbuf->b_prompt_start.mark.lnum) {
curwin->w_cursor.lnum = curbuf->b_prompt_start.mark.lnum;
}
char *text = get_cursor_line_ptr();
if ((curbuf->b_prompt_start.mark.lnum == curwin->w_cursor.lnum

View File

@@ -302,8 +302,8 @@ describe('prompt buffer', function()
{5:-- INSERT --} |
]])
-- ensure cursor gets adjusted to end of user-text to prompt when insert mode
-- is entered from readonly region of prompt buffer
-- ensure cursor gets placed on first line of user input.
-- when insert mode is entered from read-only region of prompt buffer.
local prompt_pos = api.nvim_buf_get_mark(0, ':')
feed('<esc>')
-- works before prompt
@@ -319,8 +319,8 @@ describe('prompt buffer', function()
feed('<esc>')
screen:expect([[
other buffer |
% line1 |
line^2 |
%^ line1 |
line2 |
{1:~ }|*6
|
]])
@@ -337,11 +337,40 @@ describe('prompt buffer', function()
feed('<esc>')
screen:expect([[
other buffer |
% line1 |
line^2 |
%^ line1 |
line2 |
{1:~ }|*6
|
]])
-- i_<Left> i_<C-Left> i_<Home> i_<End> keys on prompt-line doesn't put cursor
-- at end of text
feed('a<Left><C-Left>')
screen:expect([[
other buffer |
% ^line1 |
line2 |
{1:~ }|*6
{5:-- INSERT --} |
]])
feed('<End>')
screen:expect([[
other buffer |
% line1^ |
line2 |
{1:~ }|*6
{5:-- INSERT --} |
]])
feed('<Home>')
screen:expect([[
other buffer |
% ^line1 |
line2 |
{1:~ }|*6
{5:-- INSERT --} |
]])
end)
it('can put (p) multiline text', function()