From 466b2ac1929ab120642e2cc91fbf1699d6ee1f9c Mon Sep 17 00:00:00 2001 From: Shadman Date: Sat, 8 Nov 2025 08:40:37 +0600 Subject: [PATCH] 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. --- src/nvim/edit.c | 8 +--- test/functional/legacy/prompt_buffer_spec.lua | 41 ++++++++++++++++--- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 3a0cc09c10..43dcc61ece 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -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 diff --git a/test/functional/legacy/prompt_buffer_spec.lua b/test/functional/legacy/prompt_buffer_spec.lua index 2e07698f39..0eee719dea 100644 --- a/test/functional/legacy/prompt_buffer_spec.lua +++ b/test/functional/legacy/prompt_buffer_spec.lua @@ -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('') -- works before prompt @@ -319,8 +319,8 @@ describe('prompt buffer', function() feed('') screen:expect([[ other buffer | - % line1 | - line^2 | + %^ line1 | + line2 | {1:~ }|*6 | ]]) @@ -337,11 +337,40 @@ describe('prompt buffer', function() feed('') screen:expect([[ other buffer | - % line1 | - line^2 | + %^ line1 | + line2 | {1:~ }|*6 | ]]) + + -- i_ i_ i_ i_ keys on prompt-line doesn't put cursor + -- at end of text + feed('a') + screen:expect([[ + other buffer | + % ^line1 | + line2 | + {1:~ }|*6 + {5:-- INSERT --} | + ]]) + + feed('') + screen:expect([[ + other buffer | + % line1^ | + line2 | + {1:~ }|*6 + {5:-- INSERT --} | + ]]) + + feed('') + screen:expect([[ + other buffer | + % ^line1 | + line2 | + {1:~ }|*6 + {5:-- INSERT --} | + ]]) end) it('can put (p) multiline text', function()