Mercurial > vim
diff src/buffer.c @ 18864:9449ed2ee8d4 v8.1.2418
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Commit: https://github.com/vim/vim/commit/99ebf22c523e3fdb491b2c92b6f3a7d42721361d
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Dec 10 23:44:48 2019 +0100
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 https://github.com/vim/vim/issues/5335)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 10 Dec 2019 23:45:04 +0100 |
parents | 49b78d6465e5 |
children | 050f5eaa9e50 |
line wrap: on
line diff
--- a/src/buffer.c +++ b/src/buffer.c @@ -2093,6 +2093,25 @@ buflist_new( // buffer number grows rapidly. --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 buf->b_fnum = top_file_num++;