]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0787: cursor position changed when using hidden terminal v9.1.0787
authorChristian Brabandt <cb@256bit.org>
Tue, 15 Oct 2024 18:31:14 +0000 (20:31 +0200)
committerChristian Brabandt <cb@256bit.org>
Tue, 15 Oct 2024 18:38:57 +0000 (20:38 +0200)
Problem:  cursor position changed when using hidden terminal
          and BufFilePost autocommand (Mizuno Jan Yuta)
Solution: Save and restore cursor position

fixes: #15854
closes: #15876

Signed-off-by: Christian Brabandt <cb@256bit.org>
src/terminal.c
src/testdir/test_terminal3.vim
src/version.c

index 073f8dd48da44ae17c9904d06fd6f51b332933e9..f61a54f7f0d91d936bc37c09a03f31764d406b15 100644 (file)
@@ -446,6 +446,7 @@ term_start(
     buf_T      *newbuf;
     int                vertical = opt->jo_vertical || (cmdmod.cmod_split & WSP_VERT);
     jobopt_T   orig_opt;  // only partly filled
+    pos_T      save_cursor;
 
     if (check_restricted() || check_secure())
        return NULL;
@@ -518,6 +519,7 @@ term_start(
        old_curbuf = curbuf;
        --curbuf->b_nwindows;
        curbuf = buf;
+       save_cursor = curwin->w_cursor;
        curwin->w_buffer = buf;
        ++curbuf->b_nwindows;
     }
@@ -763,6 +765,7 @@ term_start(
            --curbuf->b_nwindows;
            curbuf = old_curbuf;
            curwin->w_buffer = curbuf;
+           curwin->w_cursor = save_cursor;
            ++curbuf->b_nwindows;
        }
        else if (vgetc_busy
index 3cca1b05cb8117d24f1db996a7d7ce1b8db0fc2c..5865d18f4f9250fe5aba1b07d2f512e4524a92e1 100644 (file)
@@ -975,4 +975,29 @@ func Test_terminal_vertical()
   call v9.CheckLegacyAndVim9Success(lines)
 endfunc
 
+" Needs to come before Test_hidden_terminal(), why?
+func Test_autocmd_buffilepost_with_hidden_term()
+  CheckExecutable true
+  new XTestFile
+  defer delete('XTestFile')
+  call setline(1, ['one', 'two', 'three'])
+  call cursor(3, 10)
+  augroup TestCursor
+    au!
+    autocmd BufFilePost * call setbufvar(3, '&tabstop', 4)
+  augroup END
+
+  let buf = term_start(['true'], #{hidden: 1, term_finish: 'close'})
+  call term_wait(buf)
+  redraw!
+  call assert_equal('XTestFile', bufname('%'))
+  call assert_equal([0, 3, 5, 0], getpos('.'))
+
+  augroup TestCursor
+    au!
+  augroup END
+  augroup! TestCursor
+  bw! XTestFile
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 06a52a001ee1f443c114f03e78e5ec96b9c03d4e..b8852e39b4be4efdbf3bf208d1606a2ba7ef311a 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    787,
 /**/
     786,
 /**/