Skip to content

Commit c174c2e

Browse files
committed
patch 9.0.1428: cursor in wrong position when leaving insert mode
Problem: Cursor in wrong position when leaving insert mode. Solution: Update the w_valid flags. Position the cursor also when not redrawing. (closes #12137)
1 parent 1f76138 commit c174c2e

5 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/edit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3688,6 +3688,7 @@ ins_esc(
36883688
else
36893689
{
36903690
--curwin->w_cursor.col;
3691+
curwin->w_valid &= ~(VALID_WCOL|VALID_VIRTCOL);
36913692
// Correct cursor for multi-byte character.
36923693
if (has_mbyte)
36933694
mb_adjust_cursor();

src/main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ main
305305
params.want_full_screen = FALSE;
306306

307307
/*
308-
* When certain to start the GUI, don't check capabilities of terminal.
308+
* When certain to start the GUI, don't check terminal capabilities.
309309
* For GTK we can't be sure, but when started from the desktop it doesn't
310310
* make sense to try using a terminal.
311311
*/
@@ -1290,7 +1290,11 @@ main_loop(
12901290
* update cursor and redraw.
12911291
*/
12921292
if (skip_redraw || exmode_active)
1293+
{
12931294
skip_redraw = FALSE;
1295+
setcursor();
1296+
cursor_on();
1297+
}
12941298
else if (do_redraw || stuff_empty())
12951299
{
12961300
#ifdef FEAT_GUI
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
>:+0&#ffffff0| @58
2+
|~+0#4040ff13&| @58
3+
|~| @58
4+
|~| @58
5+
|~| @58
6+
| +0#0000000&@59

src/testdir/test_edit.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ if exists("+t_kD")
55
endif
66

77
source check.vim
8+
source screendump.vim
89

910
" Needed for testing basic rightleft: Test_edit_rightleft
1011
source view_util.vim
@@ -1957,6 +1958,22 @@ func Test_edit_insert_reg()
19571958
close!
19581959
endfunc
19591960

1961+
" Test for positioning cursor after CTRL-R expression failed
1962+
func Test_edit_ctrl_r_failed()
1963+
CheckRunVimInTerminal
1964+
1965+
let buf = RunVimInTerminal('', #{rows: 6, cols: 60})
1966+
1967+
" trying to insert a dictionary produces an error
1968+
call term_sendkeys(buf, "i\<C-R>={}\<CR>")
1969+
1970+
" ending Insert mode should put the cursor back on the ':'
1971+
call term_sendkeys(buf, ":\<Esc>")
1972+
call VerifyScreenDump(buf, 'Test_edit_ctlr_r_failed_1', {})
1973+
1974+
call StopVimInTerminal(buf)
1975+
endfunc
1976+
19601977
" When a character is inserted at the last position of the last line in a
19611978
" window, the window contents should be scrolled one line up. If the top line
19621979
" is part of a fold, then the entire fold should be scrolled up.

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ static char *(features[]) =
695695

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1428,
698700
/**/
699701
1427,
700702
/**/

0 commit comments

Comments
 (0)