diff options
-rw-r--r-- | runtime/doc/autocmd.txt | 3 | ||||
-rw-r--r-- | runtime/doc/eval.txt | 17 | ||||
-rw-r--r-- | src/nvim/eval.c | 7 | ||||
-rw-r--r-- | src/nvim/eval.lua | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test_popup.vim | 42 |
5 files changed, 70 insertions, 0 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 18dfa587e8..ac61297767 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -607,6 +607,9 @@ CompleteChanged *CompleteChanged* It is not allowed to change the text |textlock|. + The size and position of the popup are also + available by calling |pum_getpos()|. + *CursorHold* CursorHold When the user doesn't press a key for the time specified with 'updatetime'. Not re-triggered diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 597175b5e5..d02ed54e27 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2280,6 +2280,7 @@ pathshorten({expr}) String shorten directory names in a path pow({x}, {y}) Float {x} to the power of {y} prevnonblank({lnum}) Number line nr of non-blank line <= {lnum} printf({fmt}, {expr1}...) String format text +pum_getpos() Dict position and size of pum if visible pumvisible() Number whether popup menu is visible pyeval({expr}) any evaluate |Python| expression py3eval({expr}) any evaluate |python3| expression @@ -3120,6 +3121,9 @@ complete_info([{what}]) the items listed in {what} are returned. Unsupported items in {what} are silently ignored. + To get the position of the popup menu, see |pum_getpos()|. It's + also available in |v:event| during the |CompleteChanged| event. + Examples: > " Get all items call complete_info() @@ -6521,6 +6525,19 @@ printf({fmt}, {expr1} ...) *printf()* arguments an error is given. Up to 18 arguments can be used. +pum_getpos() *pum_getpos()* + If the popup menu (see |ins-completion-menu|) is not visible, + returns an empty |Dictionary|, otherwise, returns a + |Dictionary| with the following keys: + height nr of items visible + width screen cells + row top screen row (0 first row) + col leftmost screen column (0 first col) + size total nr of items + scrollbar |TRUE| if visible + + The values are the same as in |v:event| during |CompleteChanged|. + pumvisible() *pumvisible()* Returns non-zero when the popup menu is visible, zero otherwise. See |ins-completion-menu|. diff --git a/src/nvim/eval.c b/src/nvim/eval.c index a556f0bbbe..4c76b1b2e8 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -13972,6 +13972,13 @@ static void f_printf(typval_T *argvars, typval_T *rettv, FunPtr fptr) } } +// "pum_getpos()" function +static void f_pum_getpos(typval_T *argvars, typval_T *rettv, FunPtr fptr) +{ + tv_dict_alloc_ret(rettv); + pum_set_event_info(rettv->vval.v_dict); +} + /* * "pumvisible()" function */ diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 0ae250e626..efeac70816 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -243,6 +243,7 @@ return { pow={args=2}, prevnonblank={args=1}, printf={args=varargs(1)}, + pum_getpos={}, pumvisible={}, py3eval={args=1}, pyeval={args=1}, diff --git a/src/nvim/testdir/test_popup.vim b/src/nvim/testdir/test_popup.vim index 8083672808..9db6112eeb 100644 --- a/src/nvim/testdir/test_popup.vim +++ b/src/nvim/testdir/test_popup.vim @@ -918,6 +918,20 @@ func Test_popup_complete_info_02() bwipe! endfunc +func Test_popup_complete_info_no_pum() + new + call assert_false( pumvisible() ) + let no_pum_info = complete_info() + let d = { + \ 'mode': '', + \ 'pum_visible': 0, + \ 'items': [], + \ 'selected': -1, + \ } + call assert_equal( d, complete_info() ) + bwipe! +endfunc + func Test_CompleteChanged() new call setline(1, ['foo', 'bar', 'foobar', '']) @@ -952,4 +966,32 @@ func Test_CompleteChanged() bw! endfunc +function! GetPumPosition() + call assert_true( pumvisible() ) + let g:pum_pos = pum_getpos() + return '' +endfunction + +func Test_pum_getpos() + new + inoremap <buffer><F5> <C-R>=GetPumPosition()<CR> + setlocal completefunc=UserDefinedComplete + + let d = { + \ 'height': 5, + \ 'width': 15, + \ 'row': 1, + \ 'col': 0, + \ 'size': 5, + \ 'scrollbar': v:false, + \ } + call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx') + call assert_equal(d, g:pum_pos) + + call assert_false( pumvisible() ) + call assert_equal( {}, pum_getpos() ) + bw! + unlet g:pum_pos +endfunc + " vim: shiftwidth=2 sts=2 expandtab |