]> granicus.if.org Git - vim/commitdiff
patch 8.1.1422: popup_getoptions() not implemented yet v8.1.1422
authorBram Moolenaar <Bram@vim.org>
Thu, 30 May 2019 12:29:45 +0000 (14:29 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 30 May 2019 12:29:45 +0000 (14:29 +0200)
Problem:    Popup_getoptions() not implemented yet.
Solution:   Implement it. (closes #4452)

runtime/doc/popup.txt
src/evalfunc.c
src/popupwin.c
src/proto/popupwin.pro
src/testdir/test_popupwin.vim
src/version.c

index c573e773903864707053b3748798b72cd96a5c91..174ea094a3ea3b9f898bab6c41b2cedf2dd31369 100644 (file)
@@ -86,15 +86,18 @@ Probably 2. is the best choice.
 IMPLEMENTATION:
 - Code is in popupwin.c
 - when creating the window set options to Vim default? (verify with 'number')
-- Do not show tilde below last line.
 - Implement filter.
   Check that popup_close() works in the filter.
+- Implement the "pos" option.
 - Handle screen resize in screenalloc().
 - Make redrawing more efficient and avoid flicker.
+    Store popup info in a mask, use the mask in screen_line()
     Fix redrawing problem with completion.
     Fix redrawing problem when scrolling non-current window
     Fix redrawing the statusline on top of a popup
-- Properly figure out the size and position.
+- Figure out the size and position better.
+    if wrapping splits a double-wide character
+    if wrapping has an indent
 - Can the buffer be re-used, to avoid using up lots of buffer numbers?
 - Implement all the unimplemented options and features.
 
@@ -228,16 +231,23 @@ popup_setoptions({id}, {options})                 *popup_setoptions()*
 
 
 popup_getoptions({id})                                 *popup_getoptions()*
-               {not implemented yet}
-               Return the {options} for popup {id}.
+               Return the {options} for popup {id} in a Dict.
+               A zero value means the option was not set.
+
+               The "highlight" entry is omitted, use the 'wincolor' option
+               for that: >
+                       let hl = getwinvar(winid, '&wincolor')
+
+<              If popup window {id} is not found an empty Dict is returned.
 
 popup_getposition({id})                                        *popup_getposition()*
                Return the position and size of popup {id}.  Returns a Dict
                with these entries:
-                       col     screen column of the popup, one-based
-                       line    screen line of the popup, one-based
-                       width   width of the popup in screen cells
-                       height  height of the popup in screen cells
+                   col         screen column of the popup, one-based
+                   line        screen line of the popup, one-based
+                   width       width of the popup in screen cells
+                   height      height of the popup in screen cells
+                   visible     one if the popup is displayed, zero if hidden
                Note that these are the actual screen positions.  They differ
                from the values in `popup_getoptions()` for the sizing and
                positioning mechanism applied.
@@ -304,9 +314,9 @@ The second argument of |popup_create()| is a dictionary with options:
                        {only number is implemented}
        pos             "topleft", "topright", "botleft" or "botright":
                        defines what corner of the popup "line" and "col" are
-                       used for.  Default is "botleft".  Alternatively
-                       "center" can be used to position the popup in the
-                       center of the Vim window.
+                       used for.  When not set "topleft" is used.
+                       Alternatively "center" can be used to position the
+                       popup in the center of the Vim window.
                        {not implemented yet}
        flip            when TRUE (the default) and the position is relative
                        to the cursor, flip to below or above the cursor to
index 2abbcfe4a005274b41c0b4686c9b8bd7bcd2abfe..7753fc65e697918a94d6a03f7b1fbc69bf24a6a9 100644 (file)
@@ -811,6 +811,7 @@ static struct fst
 #ifdef FEAT_TEXT_PROP
     {"popup_close",    1, 1, f_popup_close},
     {"popup_create",   2, 2, f_popup_create},
+    {"popup_getoptions", 1, 1, f_popup_getoptions},
     {"popup_getposition", 1, 1, f_popup_getposition},
     {"popup_hide",     1, 1, f_popup_hide},
     {"popup_move",     2, 2, f_popup_move},
index 64309ff8b794bf0efbae80d927444fb22a104c54..0ad24cf877702dc070cc0ef96df1197d53953089 100644 (file)
@@ -530,6 +530,38 @@ f_popup_getposition(typval_T *argvars, typval_T *rettv)
        dict_add_number(dict, "col", wp->w_wincol + 1);
        dict_add_number(dict, "width", wp->w_width);
        dict_add_number(dict, "height", wp->w_height);
+       dict_add_number(dict, "visible",
+                                      (wp->w_popup_flags & POPF_HIDDEN) == 0);
+    }
+}
+
+/*
+ * f_popup_getoptions({id})
+ */
+    void
+f_popup_getoptions(typval_T *argvars, typval_T *rettv)
+{
+    dict_T     *dict;
+    int                id = (int)tv_get_number(argvars);
+    win_T      *wp = find_popup_win(id);
+
+    if (rettv_dict_alloc(rettv) == OK)
+    {
+       if (wp == NULL)
+           return;
+
+       dict = rettv->vval.v_dict;
+       dict_add_number(dict, "line", wp->w_wantline);
+       dict_add_number(dict, "col", wp->w_wantcol);
+       dict_add_number(dict, "minwidth", wp->w_minwidth);
+       dict_add_number(dict, "minheight", wp->w_minheight);
+       dict_add_number(dict, "maxheight", wp->w_maxheight);
+       dict_add_number(dict, "maxwidth", wp->w_maxwidth);
+       dict_add_number(dict, "zindex", wp->w_zindex);
+# if defined(FEAT_TIMERS)
+       dict_add_number(dict, "time", wp->w_popup_timer != NULL
+                                ?  (long)wp->w_popup_timer->tr_interval : 0L);
+# endif
     }
 }
 #endif // FEAT_TEXT_PROP
index 83b5f2ccb8ec1daea6862e3457f5b36cbaa48d9f..7337457126792e0b9b80ad65098af5536a4b4676 100644 (file)
@@ -10,5 +10,6 @@ void popup_close_tabpage(tabpage_T *tp, int id);
 void close_all_popups(void);
 void ex_popupclear(exarg_T *eap);
 void f_popup_move(typval_T *argvars, typval_T *rettv);
+void f_popup_getoptions(typval_T *argvars, typval_T *rettv);
 void f_popup_getposition(typval_T *argvars, typval_T *rettv);
 /* vim: set ft=c : */
index 4511cd1ac0351b5785fe123f99000437010284c0..a11e5a03f34457d115f1016acbc0ef0d8a398a50 100644 (file)
@@ -108,16 +108,19 @@ func Test_popup_hide()
   redraw
   let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
   call assert_equal('world', line)
+  call assert_equal(1, popup_getposition(winid).visible)
 
   call popup_hide(winid)
   redraw
   let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
   call assert_equal('hello', line)
+  call assert_equal(0, popup_getposition(winid).visible)
 
   call popup_show(winid)
   redraw
   let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
   call assert_equal('world', line)
+  call assert_equal(1, popup_getposition(winid).visible)
 
 
   call popup_close(winid)
@@ -178,6 +181,7 @@ func Test_popup_getposition()
   call assert_equal(3, res.col)
   call assert_equal(10, res.width)
   call assert_equal(11, res.height)
+  call assert_equal(1, res.visible)
 
   call popup_close(winid)
 endfunc
@@ -215,5 +219,48 @@ func Test_popup_wraps()
     call assert_equal(test[2], position.height)
 
     call popup_close(winid)
+    call assert_equal({}, popup_getposition(winid))
   endfor
 endfunc
+
+func Test_popup_getoptions()
+  let winid = popup_create('hello', {
+    \ 'line': 2,
+    \ 'col': 3,
+    \ 'minwidth': 10,
+    \ 'minheight': 11,
+    \ 'maxwidth': 20,
+    \ 'maxheight': 21,
+    \ 'zindex': 100,
+    \ 'time': 5000,
+    \})
+  redraw
+  let res = popup_getoptions(winid)
+  call assert_equal(2, res.line)
+  call assert_equal(3, res.col)
+  call assert_equal(10, res.minwidth)
+  call assert_equal(11, res.minheight)
+  call assert_equal(20, res.maxwidth)
+  call assert_equal(21, res.maxheight)
+  call assert_equal(100, res.zindex)
+  if has('timers')
+    call assert_equal(5000, res.time)
+  endif
+  call popup_close(winid)
+
+  let winid = popup_create('hello', {})
+  redraw
+  let res = popup_getoptions(winid)
+  call assert_equal(0, res.line)
+  call assert_equal(0, res.col)
+  call assert_equal(0, res.minwidth)
+  call assert_equal(0, res.minheight)
+  call assert_equal(0, res.maxwidth)
+  call assert_equal(0, res.maxheight)
+  call assert_equal(50, res.zindex)
+  if has('timers')
+    call assert_equal(0, res.time)
+  endif
+  call popup_close(winid)
+  call assert_equal({}, popup_getoptions(winid))
+endfunc
index ca487930314d0b34a626c9cc88240bb48ebc86a9..8519fd5cdbbcd88955a9567f2a3831e6bc27d533 100644 (file)
@@ -767,6 +767,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1422,
 /**/
     1421,
 /**/