# HG changeset patch # User Bram Moolenaar # Date 1669579205 -3600 # Node ID 87ff5e71d3c2feea63f06f594529d9d787947e49 # Parent fac14d7d7c2b621fe4253ac311321fdc1532e425 patch 9.0.0961: using deletebufline() may jump to another window Commit: https://github.com/vim/vim/commit/3da8597fc07505c0f8839b0834aafe1c10ffb456 Author: Bram Moolenaar Date: Sun Nov 27 19:45:49 2022 +0000 patch 9.0.0961: using deletebufline() may jump to another window Problem: Using deletebufline() may jump to another window. Solution: Do not use a window where the buffer was only in the past. (closes #11594) diff --git a/src/evalbuffer.c b/src/evalbuffer.c --- a/src/evalbuffer.c +++ b/src/evalbuffer.c @@ -109,9 +109,12 @@ find_win_for_curbuf(void) { wininfo_T *wip; + // The b_wininfo list should have the windows that recently contained the + // buffer, going over this is faster than going over all the windows. + // Do check the buffer is still there. FOR_ALL_BUF_WININFO(curbuf, wip) { - if (wip->wi_win != NULL) + if (wip->wi_win != NULL && wip->wi_win->w_buffer == curbuf) { curwin = wip->wi_win; break; diff --git a/src/testdir/test_bufline.vim b/src/testdir/test_bufline.vim --- a/src/testdir/test_bufline.vim +++ b/src/testdir/test_bufline.vim @@ -288,6 +288,20 @@ func Test_deletebufline_select_mode() bwipe! endfunc +func Test_deletebufline_popup_window() + let popupID = popup_create('foo', {}) + let bufnr = winbufnr(popupID) + + " Check that deletebufline() brings us back to the same window. + new + let winid_before = win_getid() + call deletebufline(bufnr, 1, '$') + call assert_equal(winid_before, win_getid()) + bwipe + + call popup_close(popupID) +endfunc + func Test_setbufline_startup_nofile() let before =<< trim [CODE] set shortmess+=F diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -696,6 +696,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 961, +/**/ 960, /**/ 959,