@@ -26,21 +26,10 @@ function! s:create(opt) abort
2626 if s: _has_nvim
2727 let data[' bufnr' ] = nvim_create_buf (0 , 1 )
2828 call nvim_buf_set_lines (data[' bufnr' ], 0 , -1 , 1 , data[' contents' ])
29- let data[' winid' ] = s: _nvim_open_win (id, data)
29+ let data[' winid' ] = s: _nvim_open_win (data)
3030 else
3131 " neovim doesn't support scrollbar so don't enable it
32- let data[' winid' ] = popup_create (data[' contents' ], {
33- \ ' width' : data[' w' ],
34- \ ' height' : data[' h' ],
35- \ ' minwidth' : data[' w' ],
36- \ ' minheight' : data[' h' ],
37- \ ' maxwidth' : data[' w' ],
38- \ ' maxheight' : data[' h' ],
39- \ ' col' : data[' sx' ],
40- \ ' line' : data[' sy' ],
41- \ ' scrollbar' : 0 ,
42- \ ' wrap' : 0 ,
43- \ })
32+ let data[' winid' ] = popup_create (data[' contents' ], s: _get_vim_options (data))
4433 let data[' bufnr' ] = winbufnr (data[' winid' ])
4534 endif
4635 let s: _popups [id] = data
@@ -75,7 +64,7 @@ endfunction
7564function ! s: show (id) abort
7665 let data = s: _popups [a: id ]
7766 if s: _has_nvim
78- let data[' winid' ] = s: _nvim_open_win (a: id , data)
67+ let data[' winid' ] = s: _nvim_open_win (data)
7968 else
8069 call popup_show (data[' winid' ])
8170 endif
@@ -92,16 +81,43 @@ function! s:contents(id, contents) abort
9281 endif
9382endfunction
9483
84+ function ! s: options (id, opt ) abort
85+ let data = s: _popups [a: id ]
86+ call s: _set (data, a: opt )
87+ if s: _has_nvim
88+ call nvim_win_set_config (data[' winid' ], s: _get_nvim_options (data))
89+ else
90+ call popup_setoptions (data[' winid' ], s: _get_vim_options (data))
91+ endif
92+ call s: _notify (a: id , {}, ' options' )
93+ endfunction
94+
9595function ! s: winid (id) abort
96+ " can return 0 when hidden for neovim
9697 return s: _popups [a: id ][' winid' ]
9798endfunction
9899
99100function ! s: bufnr (id) abort
100101 return s: _popups [a: id ][' bufnr' ]
101102endfunction
102103
103- function ! s: _nvim_open_win (id, data) abort
104- let opt = {
104+ function ! s: _get_vim_options (data) abort
105+ return {
106+ \ ' width' : a: data [' w' ],
107+ \ ' height' : a: data [' h' ],
108+ \ ' minwidth' : a: data [' w' ],
109+ \ ' minheight' : a: data [' h' ],
110+ \ ' maxwidth' : a: data [' w' ],
111+ \ ' maxheight' : a: data [' h' ],
112+ \ ' col' : a: data [' sx' ],
113+ \ ' line' : a: data [' sy' ],
114+ \ ' scrollbar' : 0 ,
115+ \ ' wrap' : 0 ,
116+ \ }
117+ endfunction
118+
119+ function ! s: _get_nvim_options (data) abort
120+ return {
105121 \ ' relative' : ' editor' ,
106122 \ ' style' : ' minimal' ,
107123 \ ' width' : a: data [' w' ],
@@ -110,7 +126,26 @@ function! s:_nvim_open_win(id, data) abort
110126 \ ' row' : a: data [' sy' ],
111127 \ ' focusable' : 0 ,
112128 \ }
113- return nvim_open_win (a: data [' bufnr' ], 0 , opt )
129+ endfunction
130+
131+ function ! s: _nvim_open_win (data) abort
132+ return nvim_open_win (a: data [' bufnr' ], 0 , s: _get_nvim_options (a: data ))
133+ endfunction
134+
135+ function ! s: _user_to_editor_xy (val) abort
136+ if s: _has_nvim
137+ return a: val - 1
138+ else
139+ return a: val
140+ endif
141+ endfunction
142+
143+ function ! s: _editor_to_user_xy (val) abort
144+ if s: _has_nvim
145+ return a: val + 1
146+ else
147+ return a: val
148+ endif
114149endfunction
115150
116151function ! s: _set (data, opt ) abort
@@ -126,10 +161,10 @@ function! s:_set(data, opt) abort
126161 let a: data [' h' ] = get (a: opt , ' h' , get (a: data , ' h' , 5 ))
127162
128163 if s: _has_nvim
129- " a:opt[x/y] need to - 1
164+ " a:opt[x/y] need to normalize
130165 " a:data['x/y'] already normalized
131- let a: data [' x' ] = has_key (a: opt , ' x' ) ? a: opt [' x' ] - 1 : get (a: data , ' x' , 0 )
132- let a: data [' y' ] = has_key (a: opt , ' y' ) ? a: opt [' y' ] - 1 : get (a: data , ' y' , 0 )
166+ let a: data [' x' ] = has_key (a: opt , ' x' ) ? s: _user_to_editor_xy ( a: opt [' x' ]) : get (a: data , ' x' , 0 )
167+ let a: data [' y' ] = has_key (a: opt , ' y' ) ? s: _user_to_editor_xy ( a: opt [' y' ]) : get (a: data , ' y' , 0 )
133168 else
134169 let a: data [' x' ] = get (a: opt , ' x' , get (a: data , ' x' , 1 ))
135170 let a: data [' y' ] = get (a: opt , ' y' , get (a: data , ' y' , 1 ))
0 commit comments