summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-06-20 02:31:49 +0200
committerBram Moolenaar <Bram@vim.org>2019-06-20 02:31:49 +0200
commita3fce62c911c204ae144b55018f6dc9295088850 (patch)
treeb65c7ea4a00a3bc741dea05eaf04b56ae6d5d8e3 /src
parent37e66cf0f6fa482d36d67818672000fbfb37dfbb (diff)
patch 8.1.1574: tabpage option not yet implemented for popup windowv8.1.1574
Problem: Tabpage option not yet implemented for popup window. Solution: Implement tabpage option, also for popup_getoptions().
Diffstat (limited to 'src')
-rw-r--r--src/popupwin.c68
-rw-r--r--src/testdir/test_popupwin.vim14
-rw-r--r--src/version.c2
3 files changed, 67 insertions, 17 deletions
diff --git a/src/popupwin.c b/src/popupwin.c
index b1c9840d26..e1fc0a7f42 100644
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -827,11 +827,13 @@ popup_set_buffer_text(buf_T *buf, typval_T text)
static win_T *
popup_create(typval_T *argvars, typval_T *rettv, create_type_T type)
{
- win_T *wp;
- buf_T *buf;
- dict_T *d;
- int nr;
- int i;
+ win_T *wp;
+ tabpage_T *tp = NULL;
+ int tabnr;
+ buf_T *buf;
+ dict_T *d;
+ int nr;
+ int i;
// Check arguments look OK.
if (!(argvars[0].v_type == VAR_STRING && argvars[0].vval.v_string != NULL)
@@ -847,6 +849,22 @@ popup_create(typval_T *argvars, typval_T *rettv, create_type_T type)
}
d = argvars[1].vval.v_dict;
+ if (dict_find(d, (char_u *)"tabpage", -1) != NULL)
+ tabnr = (int)dict_get_number(d, (char_u *)"tabpage");
+ else if (type == TYPE_NOTIFICATION)
+ tabnr = -1; // notifications are global by default
+ else
+ tabnr = 0;
+ if (tabnr > 0)
+ {
+ tp = find_tabpage(tabnr);
+ if (tp == NULL)
+ {
+ semsg(_("E996: Tabpage not found: %d"), tabnr);
+ return NULL;
+ }
+ }
+
// Create the window and buffer.
wp = win_alloc_popup_win();
if (wp == NULL)
@@ -875,20 +893,19 @@ popup_create(typval_T *argvars, typval_T *rettv, create_type_T type)
// Avoid that 'buftype' is reset when this buffer is entered.
buf->b_p_initialized = TRUE;
- if (dict_find(d, (char_u *)"tabpage", -1) != NULL)
- nr = (int)dict_get_number(d, (char_u *)"tabpage");
- else if (type == TYPE_NOTIFICATION)
- nr = -1; // notifications are global by default
- else
- nr = 0;
-
- if (nr == 0)
+ if (tp != NULL)
+ {
+ // popup on specified tab page
+ wp->w_next = tp->tp_first_popupwin;
+ tp->tp_first_popupwin = wp;
+ }
+ else if (tabnr == 0)
{
// popup on current tab page
wp->w_next = curtab->tp_first_popupwin;
curtab->tp_first_popupwin = wp;
}
- else if (nr < 0)
+ else // (tabnr < 0)
{
win_T *prev = first_popupwin;
@@ -903,9 +920,6 @@ popup_create(typval_T *argvars, typval_T *rettv, create_type_T type)
prev->w_next = wp;
}
}
- else
- // TODO: find tab page "nr"
- emsg("Not implemented yet");
popup_set_buffer_text(buf, argvars[0]);
@@ -1592,6 +1606,7 @@ 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);
+ tabpage_T *tp;
int i;
if (rettv_dict_alloc(rettv) == OK)
@@ -1614,6 +1629,25 @@ f_popup_getoptions(typval_T *argvars, typval_T *rettv)
dict_add_number(dict, "drag", wp->w_popup_drag);
dict_add_string(dict, "highlight", wp->w_p_wcr);
+ // find the tabpage that holds this popup
+ i = 1;
+ FOR_ALL_TABPAGES(tp)
+ {
+ win_T *p;
+
+ for (p = tp->tp_first_popupwin; p != NULL; p = wp->w_next)
+ if (p->w_id == id)
+ break;
+ if (p != NULL)
+ break;
+ ++i;
+ }
+ if (tp == NULL)
+ i = -1; // must be global
+ else if (tp == curtab)
+ i = 0;
+ dict_add_number(dict, "tabpage", i);
+
get_padding_border(dict, wp->w_popup_padding, "padding");
get_padding_border(dict, wp->w_popup_border, "border");
get_borderhighlight(dict, wp);
diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim
index 7d723a0662..451f0b6b92 100644
--- a/src/testdir/test_popupwin.vim
+++ b/src/testdir/test_popupwin.vim
@@ -398,8 +398,10 @@ func Test_popup_in_tab()
let winid = popup_create("text", {})
let bufnr = winbufnr(winid)
call assert_equal(1, popup_getpos(winid).visible)
+ call assert_equal(0, popup_getoptions(winid).tabpage)
tabnew
call assert_equal(0, popup_getpos(winid).visible)
+ call assert_equal(1, popup_getoptions(winid).tabpage)
quit
call assert_equal(1, popup_getpos(winid).visible)
@@ -411,11 +413,23 @@ func Test_popup_in_tab()
" global popup is visible in any tab
let winid = popup_create("text", {'tabpage': -1})
call assert_equal(1, popup_getpos(winid).visible)
+ call assert_equal(-1, popup_getoptions(winid).tabpage)
tabnew
call assert_equal(1, popup_getpos(winid).visible)
+ call assert_equal(-1, popup_getoptions(winid).tabpage)
quit
call assert_equal(1, popup_getpos(winid).visible)
call popup_clear()
+
+ " create popup in other tab
+ tabnew
+ let winid = popup_create("text", {'tabpage': 1})
+ call assert_equal(0, popup_getpos(winid).visible)
+ call assert_equal(1, popup_getoptions(winid).tabpage)
+ quit
+ call assert_equal(1, popup_getpos(winid).visible)
+ call assert_equal(0, popup_getoptions(winid).tabpage)
+ call popup_clear()
endfunc
func Test_popup_valid_arguments()
diff --git a/src/version.c b/src/version.c
index 9060ceb4e7..41db458d6c 100644
--- a/src/version.c
+++ b/src/version.c
@@ -778,6 +778,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1574,
+/**/
1573,
/**/
1572,