0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer

Problem:    bufnr('$') is wrong after recycling popup buffer.
Solution:   Sort the buffer list by buffer number. (closes #5335)
This commit is contained in:
Bram Moolenaar
2019-12-10 23:44:48 +01:00
parent 1e46705a83
commit 99ebf22c52
3 changed files with 38 additions and 0 deletions

View File

@@ -2093,6 +2093,25 @@ buflist_new(
// buffer number grows rapidly. // buffer number grows rapidly.
--buf_reuse.ga_len; --buf_reuse.ga_len;
buf->b_fnum = ((int *)buf_reuse.ga_data)[buf_reuse.ga_len]; buf->b_fnum = ((int *)buf_reuse.ga_data)[buf_reuse.ga_len];
// Move buffer to the right place in the buffer list.
while (buf->b_prev != NULL && buf->b_fnum < buf->b_prev->b_fnum)
{
buf_T *prev = buf->b_prev;
prev->b_next = buf->b_next;
if (prev->b_next != NULL)
prev->b_next->b_prev = prev;
buf->b_next = prev;
buf->b_prev = prev->b_prev;
if (buf->b_prev != NULL)
buf->b_prev->b_next = buf;
prev->b_prev = buf;
if (lastbuf == buf)
lastbuf = prev;
if (firstbuf == prev)
firstbuf = buf;
}
} }
else else
buf->b_fnum = top_file_num++; buf->b_fnum = top_file_num++;

View File

@@ -3168,4 +3168,21 @@ func Test_popupwin_sign()
call delete('XtestPopupSign') call delete('XtestPopupSign')
endfunc endfunc
func Test_popupwin_bufnr()
let popwin = popup_create(['blah'], #{})
let popbuf = winbufnr(popwin)
split asdfasdf
let newbuf = bufnr()
call assert_true(newbuf > popbuf, 'New buffer number is higher')
call assert_equal(newbuf, bufnr('$'))
call popup_clear()
let popwin = popup_create(['blah'], #{})
" reuses previous buffer number
call assert_equal(popbuf, winbufnr(popwin))
call assert_equal(newbuf, bufnr('$'))
call popup_clear()
bwipe!
endfunc
" vim: shiftwidth=2 sts=2 " vim: shiftwidth=2 sts=2

View File

@@ -742,6 +742,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
2418,
/**/ /**/
2417, 2417,
/**/ /**/