bwipe!
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()
" run this in a separate Vim so that SafeState works
CheckRunVimInTerminal
FOR_ALL_TAB_WINDOWS(tp, wp)
if ((do_curwin || wp != curwin) && wp->w_buffer == curbuf)
{
+ int need_adjust;
+
if (!nested)
{
// save the original cursor position and topline
wp->w_save_cursor.w_topline_save = wp->w_topline;
}
- if (wp->w_cursor.lnum > curbuf->b_ml.ml_line_count)
+ 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;
- if (wp->w_topline > curbuf->b_ml.ml_line_count)
- wp->w_topline = curbuf->b_ml.ml_line_count;
+ if (need_adjust || !nested)
+ // save the (corrected) cursor position
+ wp->w_save_cursor.w_cursor_corr = wp->w_cursor;
- // save the (corrected) cursor position and topline
- wp->w_save_cursor.w_cursor_corr = wp->w_cursor;
- wp->w_save_cursor.w_topline_corr = wp->w_topline;
+ need_adjust = wp->w_topline > curbuf->b_ml.ml_line_count;
+ 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;
}
}