To: vim_dev@googlegroups.com Subject: Patch 9.0.0094 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0094 Problem: Cursor restored unexpected with nested autocommand. Solution: Do not restore the cursor when it was moved intentionally. (closes #10780) Files: src/window.c, src/testdir/test_autocmd.vim *** ../vim-9.0.0093/src/window.c 2022-07-26 13:46:53.603727842 +0100 --- src/window.c 2022-07-27 15:22:50.004608154 +0100 *************** *** 6781,6786 **** --- 6781,6788 ---- 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 *************** *** 6788,6801 **** wp->w_save_cursor.w_topline_save = wp->w_topline; } ! if (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) ! wp->w_topline = curbuf->b_ml.ml_line_count; ! // 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; } } --- 6790,6808 ---- wp->w_save_cursor.w_topline_save = wp->w_topline; } ! 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 (need_adjust || !nested) ! // save the (corrected) cursor position ! wp->w_save_cursor.w_cursor_corr = wp->w_cursor; ! 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; } } *** ../vim-9.0.0093/src/testdir/test_autocmd.vim 2022-07-26 18:12:35.094727070 +0100 --- src/testdir/test_autocmd.vim 2022-07-27 15:21:47.016795070 +0100 *************** *** 2321,2326 **** --- 2321,2337 ---- 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 *** ../vim-9.0.0093/src/version.c 2022-07-27 15:07:02.019556436 +0100 --- src/version.c 2022-07-27 15:19:17.485241696 +0100 *************** *** 737,738 **** --- 737,740 ---- { /* Add new patch number below this line */ + /**/ + 94, /**/ -- hundred-and-one symptoms of being an internet addict: 152. You find yourself falling for someone you've never seen or hardly know, but, boy can he/she TYPE!!!!!! /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///