mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 19:25:11 -07:00
vim-patch:8.1.2336: when an expr mapping moves the cursor it is not restored
Problem: When an expr mapping moves the cursor it is not restored.
Solution: Position the cursor after an expr mapping. (closes vim/vim#5256)
4ebe0e62d0
This commit is contained in:
parent
3230b31486
commit
c90cf8c77b
@ -1949,8 +1949,10 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
|
|||||||
// expression. Also save and restore the command line
|
// expression. Also save and restore the command line
|
||||||
// for "normal :".
|
// for "normal :".
|
||||||
if (mp->m_expr) {
|
if (mp->m_expr) {
|
||||||
int save_vgetc_busy = vgetc_busy;
|
const int save_vgetc_busy = vgetc_busy;
|
||||||
const bool save_may_garbage_collect = may_garbage_collect;
|
const bool save_may_garbage_collect = may_garbage_collect;
|
||||||
|
const int save_cursor_row = ui_current_row();
|
||||||
|
const int save_cursor_col = ui_current_col();
|
||||||
|
|
||||||
vgetc_busy = 0;
|
vgetc_busy = 0;
|
||||||
may_garbage_collect = false;
|
may_garbage_collect = false;
|
||||||
@ -1960,6 +1962,12 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
|
|||||||
save_m_str = vim_strsave(mp->m_str);
|
save_m_str = vim_strsave(mp->m_str);
|
||||||
}
|
}
|
||||||
map_str = eval_map_expr(mp, NUL);
|
map_str = eval_map_expr(mp, NUL);
|
||||||
|
|
||||||
|
// The mapping may do anything, but we expect it to take care of
|
||||||
|
// redrawing. Do put the cursor back where it was.
|
||||||
|
ui_cursor_goto(save_cursor_row, save_cursor_col);
|
||||||
|
ui_flush();
|
||||||
|
|
||||||
vgetc_busy = save_vgetc_busy;
|
vgetc_busy = save_vgetc_busy;
|
||||||
may_garbage_collect = save_may_garbage_collect;
|
may_garbage_collect = save_may_garbage_collect;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
" Tests for mappings and abbreviations
|
" Tests for mappings and abbreviations
|
||||||
|
|
||||||
source shared.vim
|
source shared.vim
|
||||||
|
source check.vim
|
||||||
|
source screendump.vim
|
||||||
|
|
||||||
func Test_abbreviation()
|
func Test_abbreviation()
|
||||||
" abbreviation with 0x80 should work
|
" abbreviation with 0x80 should work
|
||||||
@ -451,6 +453,36 @@ func Test_expr_map_gets_cursor()
|
|||||||
nunmap !
|
nunmap !
|
||||||
endfunc
|
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
|
||||||
|
|
||||||
" Test for mapping errors
|
" Test for mapping errors
|
||||||
func Test_map_error()
|
func Test_map_error()
|
||||||
call assert_fails('unmap', 'E474:')
|
call assert_fails('unmap', 'E474:')
|
||||||
|
Loading…
Reference in New Issue
Block a user