@@ -48,6 +48,7 @@ function! s:create(opt) abort
48
48
\ })
49
49
endif
50
50
let s: _popups [id] = data
51
+ call s: _notify (id, {}, ' create' )
51
52
return id
52
53
endfunction
53
54
@@ -58,11 +59,19 @@ function! s:close(id) abort
58
59
else
59
60
silent ! call popup_close (a: id )
60
61
endif
62
+ call s: _notify (a: id , {}, ' close' )
61
63
call remove (s: _popups , a: id )
62
64
endif
63
65
endfunction
64
66
65
67
function ! s: _set (data, opt ) abort
68
+ " copy all callbacks to data
69
+ for [key , Cb] in items (a: opt )
70
+ if stridx (key , ' on_' ) == 0
71
+ let a: data [key ] = Cb
72
+ endif
73
+ endfor
74
+
66
75
" try to set values from a:opt, if not set from a:data, if not default
67
76
let a: data [' w' ] = get (a: opt , ' w' , get (a: data , ' w' , 5 ))
68
77
let a: data [' h' ] = get (a: opt , ' h' , get (a: data , ' h' , 5 ))
@@ -103,6 +112,16 @@ function! s:_set(data, opt) abort
103
112
endif
104
113
endfunction
105
114
115
+ function ! s: _notify (id, data, event ) abort
116
+ if has_key (s: _popups [a: id ], ' on_event' )
117
+ call s: _popups [a: id ][' on_event' ](a: id , a: data , a: event )
118
+ endif
119
+ let eventhandler = ' on_' . a: event
120
+ if has_key (s: _popups [a: id ], eventhandler )
121
+ call s: _popups [a: id ][eventhandler ](a: id , a: data , a: event )
122
+ endif
123
+ endfunction
124
+
106
125
let &cpo = s: save_cpo
107
126
unlet s: save_cpo
108
127
" vim: sts=2 sw=2 smarttab et ai textwidth=0 fdm=marker
0 commit comments