vim-patch:8.2.0991: cannot get window type for autocmd and preview window

Problem:    Cannot get window type for autocmd and preview window.
Solution:   Add types to win_gettype(). (Yegappan Lakshmanan, closes vim/vim#6277)
0fe937fd86

Cherry-pick test_preview.vim,test_window_cmd.vim changes
from patch v8.2.0522.
This commit is contained in:
Jan Edmund Lazo 2020-11-25 02:27:10 -05:00
parent ede747c2cc
commit 9b2efe6b7d
No known key found for this signature in database
GPG Key ID: 64915E6E9F735B15
5 changed files with 74 additions and 34 deletions

View File

@ -9280,7 +9280,10 @@ win_getid([{win} [, {tab}]]) *win_getid()*
win_gettype([{nr}]) *win_gettype()*
Return the type of the window:
"aucmdwin" autocommand window. Temporary window
used to execute autocommands.
"popup" popup window |popup|
"preview" preview window |preview-window|
"command" command-line window |cmdwin|
(empty) normal window
"unknown" window {nr} not found

View File

@ -11006,7 +11006,11 @@ static void f_win_gettype(typval_T *argvars, typval_T *rettv, FunPtr fptr)
return;
}
}
if (wp->w_floating) {
if (wp == aucmd_win) {
rettv->vval.v_string = vim_strsave((char_u *)"aucmdwin");
} else if (wp->w_p_pvw) {
rettv->vval.v_string = vim_strsave((char_u *)"preview");
} else if (wp->w_floating) {
rettv->vval.v_string = vim_strsave((char_u *)"popup");
} else if (wp == curwin && cmdwin_type != 0) {
rettv->vval.v_string = vim_strsave((char_u *)"command");

View File

@ -1934,4 +1934,26 @@ func Test_autocmd_sigusr1()
unlet g:sigusr1_passed
endfunc
" Test for the temporary internal window used to execute autocmds
func Test_autocmd_window()
%bw!
edit one.txt
tabnew two.txt
let g:blist = []
augroup aucmd_win_test
au!
au BufEnter * call add(g:blist, [expand('<afile>'),
\ win_gettype(bufwinnr(expand('<afile>')))])
augroup END
doautoall BufEnter
call assert_equal([['one.txt', 'aucmdwin'], ['two.txt', '']], g:blist)
augroup aucmd_win_test
au!
augroup END
augroup! aucmd_win_test
%bw!
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -11,3 +11,47 @@ func Test_Psearch()
call assert_equal(wincount, winnr('$'))
bwipe
endfunc
func Test_window_preview()
" Open a preview window
pedit Xa
call assert_equal(2, winnr('$'))
call assert_equal(0, &previewwindow)
" Go to the preview window
wincmd P
call assert_equal(1, &previewwindow)
call assert_equal('preview', win_gettype())
" Close preview window
wincmd z
call assert_equal(1, winnr('$'))
call assert_equal(0, &previewwindow)
call assert_fails('wincmd P', 'E441:')
endfunc
func Test_window_preview_from_help()
filetype on
call writefile(['/* some C code */'], 'Xpreview.c')
help
pedit Xpreview.c
wincmd P
call assert_equal(1, &previewwindow)
call assert_equal('c', &filetype)
wincmd z
filetype off
close
call delete('Xpreview.c')
endfunc
func Test_multiple_preview_windows()
new
set previewwindow
new
call assert_fails('set previewwindow', 'E590:')
%bw!
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -172,39 +172,6 @@ func Test_window_split_edit_bufnr()
%bw!
endfunc
func Test_window_preview()
" Open a preview window
pedit Xa
call assert_equal(2, winnr('$'))
call assert_equal(0, &previewwindow)
" Go to the preview window
wincmd P
call assert_equal(1, &previewwindow)
" Close preview window
wincmd z
call assert_equal(1, winnr('$'))
call assert_equal(0, &previewwindow)
call assert_fails('wincmd P', 'E441:')
endfunc
func Test_window_preview_from_help()
filetype on
call writefile(['/* some C code */'], 'Xpreview.c')
help
pedit Xpreview.c
wincmd P
call assert_equal(1, &previewwindow)
call assert_equal('c', &filetype)
wincmd z
filetype off
close
call delete('Xpreview.c')
endfunc
func Test_window_exchange()
e Xa