@@ -26,21 +26,10 @@ function! s:create(opt) abort
26
26
if s: _has_nvim
27
27
let data[' bufnr' ] = nvim_create_buf (0 , 1 )
28
28
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)
30
30
else
31
31
" 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))
44
33
let data[' bufnr' ] = winbufnr (data[' winid' ])
45
34
endif
46
35
let s: _popups [id] = data
@@ -75,7 +64,7 @@ endfunction
75
64
function ! s: show (id) abort
76
65
let data = s: _popups [a: id ]
77
66
if s: _has_nvim
78
- let data[' winid' ] = s: _nvim_open_win (a: id , data)
67
+ let data[' winid' ] = s: _nvim_open_win (data)
79
68
else
80
69
call popup_show (data[' winid' ])
81
70
endif
@@ -92,16 +81,43 @@ function! s:contents(id, contents) abort
92
81
endif
93
82
endfunction
94
83
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
+
95
95
function ! s: winid (id) abort
96
+ " can return 0 when hidden for neovim
96
97
return s: _popups [a: id ][' winid' ]
97
98
endfunction
98
99
99
100
function ! s: bufnr (id) abort
100
101
return s: _popups [a: id ][' bufnr' ]
101
102
endfunction
102
103
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 {
105
121
\ ' relative' : ' editor' ,
106
122
\ ' style' : ' minimal' ,
107
123
\ ' width' : a: data [' w' ],
@@ -110,7 +126,26 @@ function! s:_nvim_open_win(id, data) abort
110
126
\ ' row' : a: data [' sy' ],
111
127
\ ' focusable' : 0 ,
112
128
\ }
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
114
149
endfunction
115
150
116
151
function ! s: _set (data, opt ) abort
@@ -126,10 +161,10 @@ function! s:_set(data, opt) abort
126
161
let a: data [' h' ] = get (a: opt , ' h' , get (a: data , ' h' , 5 ))
127
162
128
163
if s: _has_nvim
129
- " a:opt[x/y] need to - 1
164
+ " a:opt[x/y] need to normalize
130
165
" 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 )
133
168
else
134
169
let a: data [' x' ] = get (a: opt , ' x' , get (a: data , ' x' , 1 ))
135
170
let a: data [' y' ] = get (a: opt , ' y' , get (a: data , ' y' , 1 ))
0 commit comments