]> granicus.if.org Git - vim/commitdiff
patch 8.2.2695: cursor position reset with nested autocommands v8.2.2695
authorBram Moolenaar <Bram@vim.org>
Sat, 3 Apr 2021 11:19:26 +0000 (13:19 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 3 Apr 2021 11:19:26 +0000 (13:19 +0200)
Problem:    Cursor position reset with nested autocommands.
Solution:   Only check and reset line numbers for not nested autocommands.
            (closes #5820)

src/autocmd.c
src/testdir/test_terminal.vim
src/version.c

index ede8e7dbe0b7d3ceaae9717cf815cd7e689c89fa..4c12e729e0bee118a3fb79c99d236e721bcf81f1 100644 (file)
@@ -2116,14 +2116,16 @@ apply_autocmds_group(
            ap->last = FALSE;
        ap->last = TRUE;
 
-       // make sure cursor and topline are valid
-       check_lnums(TRUE);
+       if (nesting == 1)
+           // make sure cursor and topline are valid
+           check_lnums(TRUE);
 
        do_cmdline(NULL, getnextac, (void *)&patcmd,
                                     DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
 
-       // restore cursor and topline, unless they were changed
-       reset_lnums();
+       if (nesting == 1)
+           // restore cursor and topline, unless they were changed
+           reset_lnums();
 
 #ifdef FEAT_EVAL
        if (eap != NULL)
index a82ad8c52badf40b3e8de4b07d08eb0e2aff871e..e3a4b6e6a98bbaff3607d17dade9e67914ca6cb2 100644 (file)
@@ -2002,5 +2002,32 @@ func Test_terminal_all_ansi_colors()
   call delete('Xcolorscript')
 endfunc
 
+function On_BufFilePost()
+    doautocmd <nomodeline> User UserEvent
+endfunction
+
+func Test_terminal_nested_autocmd()
+  new
+  call setline(1, range(500))
+  $
+  let lastline = line('.')
+
+  augroup TermTest
+    autocmd BufFilePost * call On_BufFilePost()
+    autocmd User UserEvent silent
+  augroup END
+
+  let cmd = Get_cat_123_cmd()
+  let buf = term_start(cmd, #{term_finish: 'close', hidden: 1})
+  call assert_equal(lastline, line('.'))
+
+  call TermWait(buf)
+  exe buf . 'bwipe'
+  call delete('Xtext')
+  augroup TermTest
+    au!
+  augroup END
+endfunc
+
 
 " vim: shiftwidth=2 sts=2 expandtab
index 661a93cd8d60058804aceeabbd7add211e914eb5..1eeaaa6f54d943a1f55f20d9c41838a6ebd65d29 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2695,
 /**/
     2694,
 /**/