]> granicus.if.org Git - vim/commitdiff
patch 8.1.2336: when an expr mapping moves the cursor it is not restored v8.1.2336
authorBram Moolenaar <Bram@vim.org>
Fri, 22 Nov 2019 19:55:40 +0000 (20:55 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 22 Nov 2019 19:55:40 +0000 (20:55 +0100)
Problem:    When an expr mapping moves the cursor it is not restored.
Solution:   Position the cursor after an expr mapping. (closes #5256)

src/getchar.c
src/testdir/dumps/Test_map_expr_1.dump [new file with mode: 0644]
src/testdir/test_mapping.vim
src/version.c

index 475ee7efe726064cb93f3b23ed8e95e9489d2392..b086126d9aad1c70936e5da275ce353ddd179e70 100644 (file)
@@ -2594,6 +2594,8 @@ handle_mapping(
        {
            int save_vgetc_busy = vgetc_busy;
            int save_may_garbage_collect = may_garbage_collect;
+           int was_screen_col = screen_cur_col;
+           int was_screen_row = screen_cur_row;
 
            vgetc_busy = 0;
            may_garbage_collect = FALSE;
@@ -2602,6 +2604,11 @@ handle_mapping(
            save_m_str = vim_strsave(mp->m_str);
            map_str = eval_map_expr(save_m_str, NUL);
 
+           // The mapping may do anything, but we expect it to take care of
+           // redrawing.  Do put the cursor back where it was.
+           windgoto(was_screen_row, was_screen_col);
+           out_flush();
+
            vgetc_busy = save_vgetc_busy;
            may_garbage_collect = save_may_garbage_collect;
        }
diff --git a/src/testdir/dumps/Test_map_expr_1.dump b/src/testdir/dumps/Test_map_expr_1.dump
new file mode 100644 (file)
index 0000000..15b772e
--- /dev/null
@@ -0,0 +1,10 @@
+|o+0&#ffffff0|n|e| @71
+>t|w|o| @71
+|t|h|r|e@1| @69
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|[+0#ffffff16#e000002|o|n|]| @70
+| +0#0000000#ffffff0@74
index 4ba3645981b61a88d6fbf1fb0b59c48b13fae36a..d3abaff9bfd19681d757d800cec74b97b074561a 100644 (file)
@@ -2,6 +2,7 @@
 
 source shared.vim
 source check.vim
+source screendump.vim
 
 func Test_abbreviation()
   " abbreviation with 0x80 should work
@@ -461,3 +462,33 @@ func Test_list_mappings()
   iunmap <S-/>
   call assert_equal(['No mapping found'], execute('imap')->trim()->split("\n"))
 endfunc
+
+func Test_expr_map_restore_cursor()
+  CheckScreendump
+
+  let lines =<< trim END
+      call setline(1, ['one', 'two', 'three'])
+      2
+      set ls=2
+      hi! link StatusLine ErrorMsg
+      noremap <expr> <C-B> Func()
+      func Func()
+         let g:on = !get(g:, 'on', 0)
+         redraws
+         return ''
+      endfunc
+      func Status()
+         return get(g:, 'on', 0) ? '[on]' : ''
+      endfunc
+      set stl=%{Status()}
+  END
+  call writefile(lines, 'XtestExprMap')
+  let buf = RunVimInTerminal('-S XtestExprMap', #{rows: 10})
+  call term_wait(buf)
+  call term_sendkeys(buf, "\<C-B>")
+  call VerifyScreenDump(buf, 'Test_map_expr_1', {})
+
+  " clean up
+  call StopVimInTerminal(buf)
+  call delete('XtestExprMap')
+endfunc
index 06edccdae9d075ef2cebf27a8024c0c5156c4782..137db0ec2ef151ba51cc881e5ae027d5d18f7180 100644 (file)
@@ -737,6 +737,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2336,
 /**/
     2335,
 /**/