Skip to content

Commit 8adc8d9

Browse files
committed
patch 8.2.1997: window changes when using bufload() while in a terminal popup
Problem: Window changes when using bufload() while in a terminal popup. Solution: When searching for a window by ID also find a popup window. (closes #7307)
1 parent 193f620 commit 8adc8d9

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/testdir/test_terminal.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,23 @@ func Test_terminal_popup_with_cmd()
12371237
unlet s:winid
12381238
endfunc
12391239

1240+
func Test_terminal_popup_bufload()
1241+
let termbuf = term_start(&shell, #{hidden: v:true, term_finish: 'close'})
1242+
let winid = popup_create(termbuf, {})
1243+
sleep 50m
1244+
1245+
let newbuf = bufadd('')
1246+
call bufload(newbuf)
1247+
call setbufline(newbuf, 1, 'foobar')
1248+
1249+
" must not have switched to another window
1250+
call assert_equal(winid, win_getid())
1251+
1252+
call feedkeys("exit\<CR>", 'xt')
1253+
sleep 50m
1254+
exe 'bwipe! ' .. newbuf
1255+
endfunc
1256+
12401257
func Test_terminal_popup_insert_cmd()
12411258
CheckUnix
12421259

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
1997,
753755
/**/
754756
1996,
755757
/**/

src/window.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,7 @@ win_valid(win_T *win)
14621462

14631463
/*
14641464
* Find window "id" in the current tab page.
1465+
* Also find popup windows.
14651466
* Return NULL if not found.
14661467
*/
14671468
win_T *
@@ -1472,6 +1473,14 @@ win_find_by_id(int id)
14721473
FOR_ALL_WINDOWS(wp)
14731474
if (wp->w_id == id)
14741475
return wp;
1476+
#ifdef FEAT_PROP_POPUP
1477+
FOR_ALL_POPUPWINS(wp)
1478+
if (wp->w_id == id)
1479+
return wp;
1480+
FOR_ALL_POPUPWINS_IN_TAB(curtab, wp)
1481+
if (wp->w_id == id)
1482+
return wp;
1483+
#endif
14751484
return NULL;
14761485
}
14771486

0 commit comments

Comments
 (0)