Skip to content

Commit 2d4c992

Browse files
committed
fix(input): use correct grid when restoring cursor for <expr> mapping
1 parent b20b282 commit 2d4c992

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/nvim/getchar.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2122,6 +2122,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
21222122
const bool save_may_garbage_collect = may_garbage_collect;
21232123
const int save_cursor_row = ui_current_row();
21242124
const int save_cursor_col = ui_current_col();
2125+
const handle_T save_cursor_grid = ui_cursor_grid();
21252126
const int prev_did_emsg = did_emsg;
21262127

21272128
vgetc_busy = 0;
@@ -2135,7 +2136,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
21352136

21362137
// The mapping may do anything, but we expect it to take care of
21372138
// redrawing. Do put the cursor back where it was.
2138-
ui_cursor_goto(save_cursor_row, save_cursor_col);
2139+
ui_grid_cursor_goto(save_cursor_grid, save_cursor_row, save_cursor_col);
21392140
ui_flush();
21402141

21412142
// If an error was displayed and the expression returns an empty

src/nvim/ui.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,11 @@ int ui_current_col(void)
495495
return cursor_col;
496496
}
497497

498+
handle_T ui_cursor_grid(void)
499+
{
500+
return cursor_grid_handle;
501+
}
502+
498503
void ui_flush(void)
499504
{
500505
cmdline_ui_flush();

test/functional/ex_cmds/map_spec.lua

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ n asdf1 qwert
8686
end)
8787
end)
8888

89-
describe(':*map cursor and redrawing', function()
89+
describe('Screen', function()
9090
local screen
9191
before_each(function()
9292
clear()
@@ -149,6 +149,18 @@ describe(':*map cursor and redrawing', function()
149149
]])
150150
end)
151151

152+
it('cursor position does not move after empty-string :cmap <expr> #19046', function()
153+
command([[cnoremap <expr> <F2> '']])
154+
feed(':<F2>')
155+
screen:expect([[
156+
|
157+
~ |
158+
~ |
159+
~ |
160+
:^ |
161+
]])
162+
end)
163+
152164
it('cursor is restored after :map <expr> which redraws statusline vim-patch:8.1.2336', function()
153165
exec([[
154166
call setline(1, ['one', 'two', 'three'])
@@ -157,12 +169,12 @@ describe(':*map cursor and redrawing', function()
157169
hi! link StatusLine ErrorMsg
158170
noremap <expr> <C-B> Func()
159171
func Func()
160-
let g:on = !get(g:, 'on', 0)
161-
redraws
162-
return ''
172+
let g:on = !get(g:, 'on', 0)
173+
redraws
174+
return ''
163175
endfunc
164176
func Status()
165-
return get(g:, 'on', 0) ? '[on]' : ''
177+
return get(g:, 'on', 0) ? '[on]' : ''
166178
endfunc
167179
set stl=%{Status()}
168180
]])

0 commit comments

Comments
 (0)