# HG changeset patch # User Bram Moolenaar # Date 1559154605 -7200 # Node ID 5cebaecad422c64be60e6f71cc4c48c5f5cf16de # Parent 1a8e924e66bab5f6f0e08df06fac3fa2b13423b3 patch 8.1.1416: popup_getposition() not implemented yet commit https://github.com/vim/vim/commit/bc133543b8b0ebb1d8624e37d840b739eb00f3f3 Author: Bram Moolenaar Date: Wed May 29 20:26:46 2019 +0200 patch 8.1.1416: popup_getposition() not implemented yet Problem: Popup_getposition() not implemented yet. Solution: Implement it. (Yasuhiro Matsumoto, closes https://github.com/vim/vim/issues/4449) diff --git a/runtime/doc/popup.txt b/runtime/doc/popup.txt --- a/runtime/doc/popup.txt +++ b/runtime/doc/popup.txt @@ -84,11 +84,17 @@ Probably 2. is the best choice. IMPLEMENTATION: - Code is in popupwin.c -- implement popup_getposition({id}), use in tests +- 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. - Handle screen resize in screenalloc(). - Make redrawing more efficient and avoid flicker. + 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. +- Can the buffer be re-used, to avoid using up lots of buffer numbers? - Implement all the unimplemented options and features. @@ -225,13 +231,16 @@ popup_getoptions({id}) *popup_getopt Return the {options} for popup {id}. popup_getposition({id}) *popup_getposition()* - {not implemented yet} 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 + Note that these are the actual screen positions. They differ + from the values in `popup_getoptions()` for the sizing and + positioning mechanism applied. + If popup window {id} is not found an empty Dict is returned. win_execute({id}, {command}) {not implemented yet} diff --git a/src/evalfunc.c b/src/evalfunc.c --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -810,6 +810,7 @@ static struct fst #ifdef FEAT_TEXT_PROP {"popup_close", 1, 1, f_popup_close}, {"popup_create", 2, 2, f_popup_create}, + {"popup_getposition", 1, 1, f_popup_getposition}, {"popup_hide", 1, 1, f_popup_hide}, {"popup_move", 2, 2, f_popup_move}, {"popup_show", 1, 1, f_popup_show}, diff --git a/src/popupwin.c b/src/popupwin.c --- a/src/popupwin.c +++ b/src/popupwin.c @@ -487,4 +487,25 @@ f_popup_move(typval_T *argvars, typval_T redraw_all_later(NOT_VALID); } +/* + * popup_getposition({id}) + */ + void +f_popup_getposition(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; // invalid {id} + dict = rettv->vval.v_dict; + dict_add_number(dict, "line", wp->w_winrow + 1); + 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); + } +} #endif // FEAT_TEXT_PROP diff --git a/src/proto/popupwin.pro b/src/proto/popupwin.pro --- a/src/proto/popupwin.pro +++ b/src/proto/popupwin.pro @@ -3,6 +3,7 @@ void f_popup_create(typval_T *argvars, t int popup_any_visible(void); void f_popup_close(typval_T *argvars, typval_T *rettv); void f_popup_hide(typval_T *argvars, typval_T *rettv); +void f_popup_getposition(typval_T *argvars, typval_T *rettv); void f_popup_show(typval_T *argvars, typval_T *rettv); void popup_close(int id); void popup_close_tabpage(tabpage_T *tp, int id); diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim --- a/src/testdir/test_popupwin.vim +++ b/src/testdir/test_popupwin.vim @@ -159,3 +159,20 @@ func Test_popup_move() bwipe! endfunc + +func Test_popup_getposition() + let winid = popup_create('hello', { + \ 'line': 2, + \ 'col': 3, + \ 'minwidth': 10, + \ 'minheight': 11, + \}) + redraw + let res = popup_getposition(winid) + call assert_equal(2, res.line) + call assert_equal(3, res.col) + call assert_equal(10, res.width) + call assert_equal(11, res.height) + + call popup_close(winid) +endfunc diff --git a/src/version.c b/src/version.c --- 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 */ /**/ + 1416, +/**/ 1415, /**/ 1414,