patch 8.1.1422: popup_getoptions() not implemented yet
Problem: Popup_getoptions() not implemented yet.
Solution: Implement it. (closes #4452)
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 2abbcfe..7753fc6 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -811,6 +811,7 @@
#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},
diff --git a/src/popupwin.c b/src/popupwin.c
index 64309ff..0ad24cf 100644
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -530,6 +530,38 @@
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
diff --git a/src/proto/popupwin.pro b/src/proto/popupwin.pro
index 83b5f2c..7337457 100644
--- a/src/proto/popupwin.pro
+++ b/src/proto/popupwin.pro
@@ -10,5 +10,6 @@
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 : */
diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim
index 4511cd1..a11e5a0 100644
--- a/src/testdir/test_popupwin.vim
+++ b/src/testdir/test_popupwin.vim
@@ -108,16 +108,19 @@
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 @@
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 @@
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
diff --git a/src/version.c b/src/version.c
index ca48793..8519fd5 100644
--- a/src/version.c
+++ b/src/version.c
@@ -768,6 +768,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1422,
+/**/
1421,
/**/
1420,