]> granicus.if.org Git - vim/commitdiff
patch 8.1.1875: cannot get size and position of the popup menu v8.1.1875
authorBram Moolenaar <Bram@vim.org>
Sat, 17 Aug 2019 17:36:06 +0000 (19:36 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 17 Aug 2019 17:36:06 +0000 (19:36 +0200)
Problem:    Cannot get size and position of the popup menu.
Solution:   Add pum_getpos(). (Ben Jackson, closes #4827)

runtime/doc/autocmd.txt
runtime/doc/eval.txt
src/evalfunc.c
src/testdir/test_popup.vim
src/version.c

index 0cab9d88c1e9f134ade7664592f084f844d08630..78936519f24053c40fcda245d629b38bfaef22fe 100644 (file)
@@ -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
index 4bc4287cae02d77b18f919eba405d47cd7bf922a..1e5b5a0a0d486646b49e9afc68d2ed852a7403dd 100644 (file)
@@ -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,10 @@ complete_info([{what}])
                the items listed in {what} are returned.  Unsupported items in
                {what} are silently ignored.
 
+               To get the position and size 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 +6982,20 @@ 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|.
index f11756340614a73205549916df4c4bb233bf2bda..89430937f2abdd29c9b8b63203b0591cd8010d77 100644 (file)
@@ -234,6 +234,7 @@ 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);
+static void f_pum_getpos(typval_T *argvars, typval_T *rettv);
 static void f_pumvisible(typval_T *argvars, typval_T *rettv);
 #ifdef FEAT_PYTHON3
 static void f_py3eval(typval_T *argvars, typval_T *rettv);
@@ -741,6 +742,7 @@ static funcentry_T global_functions[] =
     {"prop_type_get",  1, 2, 0,          f_prop_type_get},
     {"prop_type_list", 0, 1, 0,          f_prop_type_list},
 #endif
+    {"pum_getpos",     0, 0, 0,          f_pum_getpos},
     {"pumvisible",     0, 0, 0,          f_pumvisible},
 #ifdef FEAT_PYTHON3
     {"py3eval",                1, 1, 0,          f_py3eval},
@@ -7960,6 +7962,19 @@ f_printf(typval_T *argvars, typval_T *rettv)
     did_emsg |= saved_did_emsg;
 }
 
+/*
+ * "pum_getpos()" function
+ */
+    static void
+f_pum_getpos(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
+{
+    if (rettv_dict_alloc(rettv) != OK)
+       return;
+#ifdef FEAT_INS_EXPAND
+    pum_set_event_info(rettv->vval.v_dict);
+#endif
+}
+
 /*
  * "pumvisible()" function
  */
index e7b4c7246da0d801477df2005307cd8874c551c1..d9f561bc7f6c2ff8fbe06d3d37e5dcc4d142812a 100644 (file)
@@ -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', ''])
@@ -1063,8 +1077,36 @@ func Test_CompleteChanged()
 
   autocmd! AAAAA_Group
   set complete& completeopt&
-  delfunc! OnPumchange
+  delfunc! OnPumChange
+  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
index 875342178c4adbe710e8f0bac7ac6795d8dbb4bb..2c02209f0571f90b6aca733afb7f589bc7884cda 100644 (file)
@@ -769,6 +769,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1875,
 /**/
     1874,
 /**/