Merge pull request #18199 from zeertzjq/vim-8.2.4797

vim-patch:8.2.4797: getwininfo() may get oudated values
This commit is contained in:
zeertzjq 2022-04-21 08:06:18 +08:00 committed by GitHub
commit db851cb105
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 5 deletions

View File

@ -6401,6 +6401,9 @@ dict_T *get_win_info(win_T *wp, int16_t tpnr, int16_t winnr)
{
dict_T *const dict = tv_dict_alloc();
// make sure w_botline is valid
validate_botline(wp);
tv_dict_add_nr(dict, S_LEN("tabnr"), tpnr);
tv_dict_add_nr(dict, S_LEN("winnr"), winnr);
tv_dict_add_nr(dict, S_LEN("winid"), wp->handle);

View File

@ -145,6 +145,13 @@ function Test_get_win_options()
endif
endfunc
function Test_getbufinfo_lastused()
new Xfoo
let info = getbufinfo('Xfoo')[0]
call assert_equal(has_key(info, 'lastused'), 1)
call assert_equal(type(info.lastused), type(0))
endfunc
func Test_getbufinfo_lines()
new Xfoo
call setline(1, ['a', 'bc', 'd'])
@ -155,9 +162,26 @@ func Test_getbufinfo_lines()
bw!
endfunc
function Test_getbufinfo_lastused()
new Xfoo
let info = getbufinfo('Xfoo')[0]
call assert_equal(has_key(info, 'lastused'), 1)
call assert_equal(type(info.lastused), type(0))
func Test_getwininfo_au()
enew
call setline(1, range(1, 16))
let g:info = #{}
augroup T1
au!
au WinEnter * let g:info = getwininfo(win_getid())[0]
augroup END
4split
" Check that calling getwininfo() from WinEnter returns fresh values for
" topline and botline.
call assert_equal(1, g:info.topline)
call assert_equal(4, g:info.botline)
close
unlet g:info
augroup! T1
bwipe!
endfunc
" vim: shiftwidth=2 sts=2 expandtab