Skip to content

Commit 991657e

Browse files
committed
patch 9.1.0787: cursor position changed when using hidden terminal
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 <[email protected]>
1 parent 6a1deaf commit 991657e

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/terminal.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ term_start(
446446
buf_T *newbuf;
447447
int vertical = opt->jo_vertical || (cmdmod.cmod_split & WSP_VERT);
448448
jobopt_T orig_opt; // only partly filled
449+
pos_T save_cursor;
449450

450451
if (check_restricted() || check_secure())
451452
return NULL;
@@ -518,6 +519,7 @@ term_start(
518519
old_curbuf = curbuf;
519520
--curbuf->b_nwindows;
520521
curbuf = buf;
522+
save_cursor = curwin->w_cursor;
521523
curwin->w_buffer = buf;
522524
++curbuf->b_nwindows;
523525
}
@@ -763,6 +765,7 @@ term_start(
763765
--curbuf->b_nwindows;
764766
curbuf = old_curbuf;
765767
curwin->w_buffer = curbuf;
768+
curwin->w_cursor = save_cursor;
766769
++curbuf->b_nwindows;
767770
}
768771
else if (vgetc_busy

src/testdir/test_terminal3.vim

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,4 +975,29 @@ func Test_terminal_vertical()
975975
call v9.CheckLegacyAndVim9Success(lines)
976976
endfunc
977977

978+
" Needs to come before Test_hidden_terminal(), why?
979+
func Test_autocmd_buffilepost_with_hidden_term()
980+
CheckExecutable true
981+
new XTestFile
982+
defer delete('XTestFile')
983+
call setline(1, ['one', 'two', 'three'])
984+
call cursor(3, 10)
985+
augroup TestCursor
986+
au!
987+
autocmd BufFilePost * call setbufvar(3, '&tabstop', 4)
988+
augroup END
989+
990+
let buf = term_start(['true'], #{hidden: 1, term_finish: 'close'})
991+
call term_wait(buf)
992+
redraw!
993+
call assert_equal('XTestFile', bufname('%'))
994+
call assert_equal([0, 3, 5, 0], getpos('.'))
995+
996+
augroup TestCursor
997+
au!
998+
augroup END
999+
augroup! TestCursor
1000+
bw! XTestFile
1001+
endfunc
1002+
9781003
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
787,
707709
/**/
708710
786,
709711
/**/

0 commit comments

Comments
 (0)