mirror of
https://github.com/neovim/neovim.git
synced 2025-11-14 14:29:02 +00:00
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:
@@ -1590,12 +1590,8 @@ static void init_prompt(int cmdchar_todo)
|
|||||||
{
|
{
|
||||||
char *prompt = prompt_text();
|
char *prompt = prompt_text();
|
||||||
|
|
||||||
if (curwin->w_cursor.lnum < curbuf->b_prompt_start.mark.lnum
|
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.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);
|
|
||||||
}
|
}
|
||||||
char *text = get_cursor_line_ptr();
|
char *text = get_cursor_line_ptr();
|
||||||
if ((curbuf->b_prompt_start.mark.lnum == curwin->w_cursor.lnum
|
if ((curbuf->b_prompt_start.mark.lnum == curwin->w_cursor.lnum
|
||||||
|
|||||||
@@ -302,8 +302,8 @@ describe('prompt buffer', function()
|
|||||||
{5:-- INSERT --} |
|
{5:-- INSERT --} |
|
||||||
]])
|
]])
|
||||||
|
|
||||||
-- ensure cursor gets adjusted to end of user-text to prompt when insert mode
|
-- ensure cursor gets placed on first line of user input.
|
||||||
-- is entered from readonly region of prompt buffer
|
-- when insert mode is entered from read-only region of prompt buffer.
|
||||||
local prompt_pos = api.nvim_buf_get_mark(0, ':')
|
local prompt_pos = api.nvim_buf_get_mark(0, ':')
|
||||||
feed('<esc>')
|
feed('<esc>')
|
||||||
-- works before prompt
|
-- works before prompt
|
||||||
@@ -319,8 +319,8 @@ describe('prompt buffer', function()
|
|||||||
feed('<esc>')
|
feed('<esc>')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
other buffer |
|
other buffer |
|
||||||
% line1 |
|
%^ line1 |
|
||||||
line^2 |
|
line2 |
|
||||||
{1:~ }|*6
|
{1:~ }|*6
|
||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
@@ -337,11 +337,40 @@ describe('prompt buffer', function()
|
|||||||
feed('<esc>')
|
feed('<esc>')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
other buffer |
|
other buffer |
|
||||||
% line1 |
|
%^ line1 |
|
||||||
line^2 |
|
line2 |
|
||||||
{1:~ }|*6
|
{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)
|
end)
|
||||||
|
|
||||||
it('can put (p) multiline text', function()
|
it('can put (p) multiline text', function()
|
||||||
|
|||||||
Reference in New Issue
Block a user