@@ -3,6 +3,7 @@ set cpo&vim
3
3
4
4
let s: _has_nvim = has (' nvim' )
5
5
let s: _popups = {}
6
+ let s: _id = 0
6
7
7
8
function ! s: is_supported () abort
8
9
return has (' nvim' ) && exists (' *nvim_open_win' ) || (! has (' nvim' ) && exists (' *popup_create' ) && has (' patch-8.2.0286' ))
@@ -17,12 +18,14 @@ endfunction
17
18
" 'pos': 'topleft|topright|bottomleft|bottomright|topcenter|bottomcenter',
18
19
" }
19
20
function ! s: create (opt ) abort
21
+ let id = s: _nextid ()
20
22
let data = {}
23
+
21
24
call s: _set (data, a: opt )
22
25
23
26
if s: _has_nvim
24
- let buf = nvim_create_buf (0 , 1 )
25
- call nvim_buf_set_lines (buf , 0 , -1 , 1 , data[' contents' ])
27
+ let data[ ' bufnr ' ] = nvim_create_buf (0 , 1 )
28
+ call nvim_buf_set_lines (data[ ' bufnr ' ] , 0 , -1 , 1 , data[' contents' ])
26
29
let opt = {
27
30
\ ' relative' : ' editor' ,
28
31
\ ' style' : ' minimal' ,
@@ -32,10 +35,10 @@ function! s:create(opt) abort
32
35
\ ' row' : data[' sy' ],
33
36
\ ' focusable' : 0 ,
34
37
\ }
35
- let id = nvim_open_win (buf , 1 , opt )
38
+ let data[ ' winid ' ] = nvim_open_win (data[ ' bufnr ' ] , 1 , opt )
36
39
else
37
40
" neovim doesn't support scrollbar so don't enable it
38
- let id = popup_create (data[' contents' ], {
41
+ let data[ ' winid ' ] = popup_create (data[' contents' ], {
39
42
\ ' width' : data[' w' ],
40
43
\ ' height' : data[' h' ],
41
44
\ ' minwidth' : data[' w' ],
@@ -46,6 +49,7 @@ function! s:create(opt) abort
46
49
\ ' line' : data[' sy' ],
47
50
\ ' scrollbar' : 0 ,
48
51
\ })
52
+ let data[' bufnr' ] = winbufnr (data[' winid' ])
49
53
endif
50
54
let s: _popups [id] = data
51
55
call s: _notify (id, {}, ' create' )
@@ -54,10 +58,11 @@ endfunction
54
58
55
59
function ! s: close (id) abort
56
60
if has_key (s: _popups , a: id )
61
+ let data = s: _popups [a: id ]
57
62
if s: _has_nvim
58
- silent ! call nvim_win_close (a: id , 1 )
63
+ call nvim_win_close (data[ ' winid ' ] , 1 )
59
64
else
60
- silent ! call popup_close (a: id )
65
+ call popup_close (data[ ' winid ' ] )
61
66
endif
62
67
call s: _notify (a: id , {}, ' close' )
63
68
call remove (s: _popups , a: id )
@@ -112,6 +117,11 @@ function! s:_set(data, opt) abort
112
117
endif
113
118
endfunction
114
119
120
+ function ! s: _nextid () abort
121
+ let s: _id += 1
122
+ return s: _id
123
+ endfunction
124
+
115
125
function ! s: _notify (id, data, event ) abort
116
126
if has_key (s: _popups [a: id ], ' on_event' )
117
127
call s: _popups [a: id ][' on_event' ](a: id , a: data , a: event )
0 commit comments