@@ -19,9 +19,32 @@ function! s:create(opt) abort
19
19
let data = {}
20
20
call s: _set_w (data, get (a: opt , ' w' , 5 ))
21
21
call s: _set_h (data, get (a: opt , ' h' , 5 ))
22
- call s: _set_contents (data, get (a: opt , ' contents' , []))
23
22
call s: _set_x (data, get (a: opt , ' x' , 1 ))
24
23
call s: _set_y (data, get (a: opt , ' y' , 1 ))
24
+ call s: _set_pos (data, get (a: opt , ' pos' , ' topleft' ))
25
+ call s: _set_contents (data, get (a: opt , ' contents' , []))
26
+
27
+ if data[' pos' ] == # ' topleft'
28
+ let data[' sx' ] = data[' x' ]
29
+ let data[' sy' ] = data[' y' ]
30
+ elseif data[' pos' ] == # ' topright'
31
+ let data[' sx' ] = data[' x' ] + data[' w' ] + 1
32
+ let data[' sy' ] = data[' y' ]
33
+ elseif data[' pos' ] == # ' bottomleft'
34
+ let data[' sx' ] = data[' x' ]
35
+ let data[' sy' ] = data[' y' ] - data[' h' ] + 1
36
+ elseif data[' pos' ] == # ' bottomright'
37
+ let data[' sx' ] = data[' x' ] + data[' w' ] + 1
38
+ let data[' sy' ] = data[' y' ] - data[' h' ] + 1
39
+ elseif data[' pos' ] == # ' topcenter'
40
+ let data[' sx' ] = data[' x' ] + float2nr (data[' x' ] / 2 ) + 1
41
+ let data[' sy' ] = data[' y' ] - data[' h' ]
42
+ elseif data[' pos' ] == # ' bottomcenter'
43
+ let data[' sx' ] = data[' x' ] + float2nr (data[' x' ] / 2 ) + 1
44
+ let data[' sy' ] = data[' y' ] + 1
45
+ else
46
+ throw ' invalid popup pos'
47
+ endif
25
48
26
49
if s: _has_nvim
27
50
let buf = nvim_create_buf (0 , 1 )
@@ -31,8 +54,8 @@ function! s:create(opt) abort
31
54
\ ' style' : ' minimal' ,
32
55
\ ' width' : data[' w' ],
33
56
\ ' height' : data[' h' ],
34
- \ ' col' : data[' x ' ],
35
- \ ' row' : data[' y ' ],
57
+ \ ' col' : data[' sx ' ],
58
+ \ ' row' : data[' sy ' ],
36
59
\ ' focusable' : 0 ,
37
60
\ }
38
61
let id = nvim_open_win (buf , 1 , opt )
@@ -45,8 +68,8 @@ function! s:create(opt) abort
45
68
\ ' minheight' : data[' h' ],
46
69
\ ' maxwidth' : data[' w' ],
47
70
\ ' maxheight' : data[' h' ],
48
- \ ' col' : data[' x ' ],
49
- \ ' line' : data[' y ' ],
71
+ \ ' col' : data[' sx ' ],
72
+ \ ' line' : data[' sy ' ],
50
73
\ ' scrollbar' : 0 ,
51
74
\ })
52
75
endif
@@ -86,6 +109,10 @@ function! s:_set_x(data, x) abort
86
109
endif
87
110
endfunction
88
111
112
+ function ! s: _set_pos (data, pos) abort
113
+ let a: data [' pos' ] = a: pos
114
+ endfunction
115
+
89
116
function ! s: close (id) abort
90
117
if has_key (s: _popups , a: id )
91
118
if s: _has_nvim
0 commit comments