summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-05-30 14:29:45 +0200
committerBram Moolenaar <Bram@vim.org>2019-05-30 14:29:45 +0200
commit8c2a600f72ca930841a5f4f7eac22884238afaf3 (patch)
treee8c7ce6db4d5ad9aac0cc7bd2d3f5581e551704a
parent1714696600f2859f897f4ffb33cedb5de09eded3 (diff)
patch 8.1.1422: popup_getoptions() not implemented yetv8.1.1422
Problem: Popup_getoptions() not implemented yet. Solution: Implement it. (closes #4452)
-rw-r--r--runtime/doc/popup.txt32
-rw-r--r--src/evalfunc.c1
-rw-r--r--src/popupwin.c32
-rw-r--r--src/proto/popupwin.pro1
-rw-r--r--src/testdir/test_popupwin.vim47
-rw-r--r--src/version.c2
6 files changed, 104 insertions, 11 deletions
diff --git a/runtime/doc/popup.txt b/runtime/doc/popup.txt
index c573e77390..174ea094a3 100644
--- a/runtime/doc/popup.txt
+++ b/runtime/doc/popup.txt
@@ -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
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 2abbcfe4a0..7753fc65e6 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -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},
diff --git a/src/popupwin.c b/src/popupwin.c
index 64309ff8b7..0ad24cf877 100644
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -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
diff --git a/src/proto/popupwin.pro b/src/proto/popupwin.pro
index 83b5f2ccb8..7337457126 100644
--- a/src/proto/popupwin.pro
+++ b/src/proto/popupwin.pro
@@ -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 : */
diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim
index 4511cd1ac0..a11e5a03f3 100644
--- a/src/testdir/test_popupwin.vim
+++ b/src/testdir/test_popupwin.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index ca48793031..8519fd5cdb 100644
--- a/src/version.c
+++ b/src/version.c
@@ -768,6 +768,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1422,
+/**/
1421,
/**/
1420,