diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 0cab9d88c1e9f1..78936519f24053 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -595,6 +595,10 @@ CompleteChanged *CompleteChanged* scrollbar TRUE if visible It is not allowed to change the text |textlock|. + + The size and position of the popup are also + available by calling |pum_getpos()|. + *CompleteDone* CompleteDone After Insert mode completion is done. Either when something was completed or abandoning diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 4bc4287cae02d7..f9295682867aae 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2613,6 +2613,7 @@ prop_type_delete({name} [, {props}]) prop_type_get([{name} [, {props}]) Dict get property type values prop_type_list([{props}]) List get list of property types +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 @@ -3477,6 +3478,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() @@ -6977,6 +6981,19 @@ prompt_setprompt({buf}, {text}) *prompt_setprompt()* < prop_ functions are documented here: |text-prop-functions|. +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/runtime/doc/tags b/runtime/doc/tags index 735a4d2d8feb5c..63a2a5e82fbca5 100644 --- a/runtime/doc/tags +++ b/runtime/doc/tags @@ -1434,6 +1434,7 @@ $VIM_POSIX vi_diff.txt /*$VIM_POSIX* --ttyfail starting.txt /*--ttyfail* --version starting.txt /*--version* --windowid starting.txt /*--windowid* +-> eval.txt /*->* -? starting.txt /*-?* -A starting.txt /*-A* -C starting.txt /*-C* @@ -3093,6 +3094,8 @@ $VIM_POSIX vi_diff.txt /*$VIM_POSIX* :spelli spell.txt /*:spelli* :spellinfo spell.txt /*:spellinfo* :spellr spell.txt /*:spellr* +:spellra spell.txt /*:spellra* +:spellrare spell.txt /*:spellrare* :spellrepall spell.txt /*:spellrepall* :spellu spell.txt /*:spellu* :spellundo spell.txt /*:spellundo* @@ -4028,6 +4031,7 @@ E271 if_ruby.txt /*E271* E272 if_ruby.txt /*E272* E273 if_ruby.txt /*E273* E274 eval.txt /*E274* +E275 textprop.txt /*E275* E277 remote.txt /*E277* E28 syntax.txt /*E28* E280 if_tcl.txt /*E280* @@ -8350,6 +8354,7 @@ prop_type_list() textprop.txt /*prop_type_list()* psql ft_sql.txt /*psql* ptcap.vim syntax.txt /*ptcap.vim* pterm-mouse options.txt /*pterm-mouse* +pum_getpos() eval.txt /*pum_getpos()* pumvisible() eval.txt /*pumvisible()* put change.txt /*put* put-Visual-mode change.txt /*put-Visual-mode* diff --git a/src/evalfunc.c b/src/evalfunc.c index f11756340614a7..1c5291f678dadf 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -234,6 +234,9 @@ static void f_pow(typval_T *argvars, typval_T *rettv); #endif static void f_prevnonblank(typval_T *argvars, typval_T *rettv); static void f_printf(typval_T *argvars, typval_T *rettv); +#ifdef FEAT_INS_EXPAND +static void f_pum_getpos(typval_T *argvars, typval_T *rettv); +#endif static void f_pumvisible(typval_T *argvars, typval_T *rettv); #ifdef FEAT_PYTHON3 static void f_py3eval(typval_T *argvars, typval_T *rettv); @@ -740,6 +743,9 @@ static funcentry_T global_functions[] = {"prop_type_delete", 1, 2, 0, f_prop_type_delete}, {"prop_type_get", 1, 2, 0, f_prop_type_get}, {"prop_type_list", 0, 1, 0, f_prop_type_list}, +#endif +#ifdef FEAT_INS_EXPAND + {"pum_getpos", 0, 0, 0, f_pum_getpos}, #endif {"pumvisible", 0, 0, 0, f_pumvisible}, #ifdef FEAT_PYTHON3 @@ -7960,6 +7966,20 @@ f_printf(typval_T *argvars, typval_T *rettv) did_emsg |= saved_did_emsg; } +#ifdef FEAT_INS_EXPAND +/* + * "pum_getpos()" function + */ + static void +f_pum_getpos(typval_T *argvars UNUSED, typval_T *rettv UNUSED) +{ + if (rettv_dict_alloc(rettv) != OK) + return; + + pum_set_event_info(rettv->vval.v_dict); +} +#endif + /* * "pumvisible()" function */ diff --git a/src/testdir/test_popup.vim b/src/testdir/test_popup.vim index e7b4c7246da0d8..eda031d08b7221 100644 --- a/src/testdir/test_popup.vim +++ b/src/testdir/test_popup.vim @@ -1033,6 +1033,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', '']) @@ -1067,4 +1081,31 @@ func Test_CompleteChanged() bw! endfunc +function! GetPumPosition() + call assert_true( pumvisible() ) + let g:pum_pos = pum_getpos() +endfunction + +func Test_Pum_GetPos() + new + inoremap =GetPumPosition() + setlocal completefunc=UserDefinedComplete + + let d = { + \ 'height': 5, + \ 'width': 15, + \ 'row': 1, + \ 'col': 0, + \ 'size': 5, + \ 'scrollbar': v:false, + \ } + call feedkeys("i\\\", '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