mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:9.0.0094: cursor restored unexpected with nested autocommand
Problem: Cursor restored unexpected with nested autocommand.
Solution: Do not restore the cursor when it was moved intentionally.
(closes vim/vim#10780)
3d6ee8bda0
This commit is contained in:
parent
394d65494a
commit
0134a2cb3e
@ -2190,6 +2190,17 @@ func Test_autocmd_nested_cursor_invalid()
|
|||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_autocmd_nested_keeps_cursor_pos()
|
||||||
|
enew
|
||||||
|
call setline(1, 'foo')
|
||||||
|
autocmd User foo ++nested normal! $a
|
||||||
|
autocmd InsertLeave * :
|
||||||
|
doautocmd User foo
|
||||||
|
call assert_equal([0, 1, 3, 0], getpos('.'))
|
||||||
|
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_autocmd_nested_switch_window()
|
func Test_autocmd_nested_switch_window()
|
||||||
" run this in a separate Vim so that SafeState works
|
" run this in a separate Vim so that SafeState works
|
||||||
CheckRunVimInTerminal
|
CheckRunVimInTerminal
|
||||||
|
@ -6866,19 +6866,26 @@ static void check_lnums_both(bool do_curwin, bool nested)
|
|||||||
wp->w_save_cursor.w_topline_save = wp->w_topline;
|
wp->w_save_cursor.w_topline_save = wp->w_topline;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wp->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
|
bool need_adjust = wp->w_cursor.lnum > curbuf->b_ml.ml_line_count;
|
||||||
|
if (need_adjust) {
|
||||||
wp->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
wp->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
||||||
}
|
}
|
||||||
if (wp->w_topline > curbuf->b_ml.ml_line_count) {
|
if (need_adjust || !nested) {
|
||||||
wp->w_topline = curbuf->b_ml.ml_line_count;
|
// save the (corrected) cursor position
|
||||||
|
wp->w_save_cursor.w_cursor_corr = wp->w_cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// save the (corrected) cursor position and topline
|
need_adjust = wp->w_topline > curbuf->b_ml.ml_line_count;
|
||||||
wp->w_save_cursor.w_cursor_corr = wp->w_cursor;
|
if (need_adjust) {
|
||||||
|
wp->w_topline = curbuf->b_ml.ml_line_count;
|
||||||
|
}
|
||||||
|
if (need_adjust || !nested) {
|
||||||
|
// save the (corrected) topline
|
||||||
wp->w_save_cursor.w_topline_corr = wp->w_topline;
|
wp->w_save_cursor.w_topline_corr = wp->w_topline;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Correct the cursor line number in other windows. Used after changing the
|
/// Correct the cursor line number in other windows. Used after changing the
|
||||||
/// current buffer, and before applying autocommands.
|
/// current buffer, and before applying autocommands.
|
||||||
|
Loading…
Reference in New Issue
Block a user