summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuuk van Baal <luukvbaal@gmail.com>2023-02-15 16:45:27 +0000
committerBram Moolenaar <Bram@vim.org>2023-02-15 16:45:27 +0000
commitbc3dc298b37820a8212e7d839e882e07d6cc98c8 (patch)
tree163ffb22feb5fd5c79ded87e7c7e36f2e0559c61
parent339e114d70de3ec2b36edf37d7ba7a7cfdf9d1a6 (diff)
downloadvim-git-bc3dc298b37820a8212e7d839e882e07d6cc98c8.tar.gz
patch 9.0.1312: Cursor position wrong when splitting window in insert modev9.0.1312
Problem: Cursor position wrong when splitting window in insert mode. Solution: Pass the actual mode to win_fix_cursor(). (Luuk van Baal, closes #11999,
-rw-r--r--src/testdir/test_window_cmd.vim9
-rw-r--r--src/version.c2
-rw-r--r--src/window.c8
3 files changed, 9 insertions, 10 deletions
diff --git a/src/testdir/test_window_cmd.vim b/src/testdir/test_window_cmd.vim
index 1441db584..969edff26 100644
--- a/src/testdir/test_window_cmd.vim
+++ b/src/testdir/test_window_cmd.vim
@@ -1753,14 +1753,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/version.c b/src/version.c
index c59a3a1df..080c3ad0c 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1312,
+/**/
1311,
/**/
1310,
diff --git a/src/window.c b/src/window.c
index 234d2a87f..e90333249 100644
--- a/src/window.c
+++ b/src/window.c
@@ -5328,7 +5328,10 @@ win_enter_ext(win_T *wp, int flags)
if (*p_spk == 'c') // assume cursor position needs updating
changed_line_abv_curs();
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));
// Now it is OK to parse messages again, which may be needed in
// autocommands.
@@ -6782,7 +6785,8 @@ 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)