commit 466b2ac1929ab120642e2cc91fbf1699d6ee1f9c
parent af5ac171bde3ae7f961a23e9464309cee7ef9c13
Author: Shadman <shadmansaleh3@gmail.com>
Date: Sat, 8 Nov 2025 08:40:37 +0600
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.
Diffstat:
2 files changed, 37 insertions(+), 12 deletions(-)
diff --git 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
@@ -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()