Skip to content

Commit 84c30d7

Browse files
add pos support
1 parent ee34ee5 commit 84c30d7

File tree

1 file changed

+32
-5
lines changed
  • autoload/vital/__vital__/Experimental/UI

1 file changed

+32
-5
lines changed

autoload/vital/__vital__/Experimental/UI/Popup.vim

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,32 @@ function! s:create(opt) abort
1919
let data = {}
2020
call s:_set_w(data, get(a:opt, 'w', 5))
2121
call s:_set_h(data, get(a:opt, 'h', 5))
22-
call s:_set_contents(data, get(a:opt, 'contents', []))
2322
call s:_set_x(data, get(a:opt, 'x', 1))
2423
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
2548

2649
if s:_has_nvim
2750
let buf = nvim_create_buf(0, 1)
@@ -31,8 +54,8 @@ function! s:create(opt) abort
3154
\ 'style': 'minimal',
3255
\ 'width': data['w'],
3356
\ 'height': data['h'],
34-
\ 'col': data['x'],
35-
\ 'row': data['y'],
57+
\ 'col': data['sx'],
58+
\ 'row': data['sy'],
3659
\ 'focusable': 0,
3760
\ }
3861
let id = nvim_open_win(buf, 1, opt)
@@ -45,8 +68,8 @@ function! s:create(opt) abort
4568
\ 'minheight': data['h'],
4669
\ 'maxwidth': data['w'],
4770
\ 'maxheight': data['h'],
48-
\ 'col': data['x'],
49-
\ 'line': data['y'],
71+
\ 'col': data['sx'],
72+
\ 'line': data['sy'],
5073
\ 'scrollbar': 0,
5174
\ })
5275
endif
@@ -86,6 +109,10 @@ function! s:_set_x(data, x) abort
86109
endif
87110
endfunction
88111

112+
function! s:_set_pos(data, pos) abort
113+
let a:data['pos'] = a:pos
114+
endfunction
115+
89116
function! s:close(id) abort
90117
if has_key(s:_popups, a:id)
91118
if s:_has_nvim

0 commit comments

Comments
 (0)