neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 0bb3a373d32e150af3909e3873be91f34df211dc
parent a2dd7fa97bab06be2b357e34af0ed0a194774d70
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Thu, 16 Feb 2023 07:41:39 +0800

vim-patch:9.0.1312: Cursor position wrong when splitting window in insert mode

Problem:    Cursor position wrong when splitting window in insert mode.
Solution:   Pass the actual mode to win_fix_cursor(). (Luuk van Baal,
            closes vim/vim#11999,

https://github.com/vim/vim/commit/bc3dc298b37820a8212e7d839e882e07d6cc98c8

Co-authored-by: Luuk van Baal <luukvbaal@gmail.com>

Diffstat:
Msrc/nvim/testdir/test_window_cmd.vim | 9+--------
Msrc/nvim/window.c | 7+++++--
2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim @@ -1653,14 +1653,7 @@ func Test_splitkeep_options() " Scroll when cursor becomes invalid in insert mode. norm Lic - call assert_equal(curpos[0], getcurpos()[0], 'run ' .. run) - - " The line number might be one less because of round-off. - call assert_inrange(curpos[1] - 1, curpos[1], getcurpos()[1], 'run ' .. run) - - call assert_equal(curpos[2], getcurpos()[2], 'run ' .. run) - call assert_equal(curpos[3], getcurpos()[3], 'run ' .. run) - call assert_equal(curpos[4], getcurpos()[4], 'run ' .. run) + call assert_equal(curpos, getcurpos(), 'run ' .. run) " No scroll when topline not equal to 1 only | execute "norm gg5\<C-e>" | split | wincmd k diff --git a/src/nvim/window.c b/src/nvim/window.c @@ -4835,7 +4835,9 @@ static void win_enter_ext(win_T *const wp, const int flags) if (*p_spk == 'c') { changed_line_abv_curs(); // assume cursor position needs updating } else { - win_fix_cursor(true); + // Make sure the cursor position is valid, either by moving the cursor + // or by scrolling the text. + win_fix_cursor(get_real_state() & (MODE_NORMAL|MODE_CMDLINE|MODE_TERMINAL)); } fix_current_dir(); @@ -6407,7 +6409,8 @@ void win_fix_scroll(int resize) /// Make sure the cursor position is valid for 'splitkeep'. /// If it is not, put the cursor position in the jumplist and move it. -/// If we are not in normal mode, scroll to make valid instead. +/// If we are not in normal mode ("normal" is zero), make it valid by scrolling +/// instead. static void win_fix_cursor(int normal) { win_T *wp = curwin;