To: vim_dev@googlegroups.com Subject: Patch 8.1.2273 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.2273 Problem: Wrong default when "pos" is changed with popup_atcursor(). Solution: Adjust the default line and col when "pos" is not the default value. (#5151) Files: runtime/doc/popup.txt, src/structs.h, src/popupwin.c, src/proto/popupwin.pro, src/ex_cmds.c, src/testdir/test_popupwin.vim, src/testdir/dumps/Test_popupwin_atcursor_pos.dump *** ../vim-8.1.2272/runtime/doc/popup.txt 2019-11-03 22:29:19.469793561 +0100 --- runtime/doc/popup.txt 2019-11-09 15:06:46.923801918 +0100 *************** *** 186,191 **** --- 186,193 ---- \ moved: 'WORD', \ }) < Use {options} to change the properties. + If "pos" is passed as "topleft" then the default for "line" + becomes "cursor+1". Can also be used as a |method|: > GetText()->popup_atcursor({}) *************** *** 305,312 **** Get the |window-ID| for the popup info window, as it used by the popup menu. See |complete-popup|. The info popup is hidden when not used, it can be deleted with |popup_clear()| ! and |popup_close()|. ! Return zero if there is none. popup_findpreview() *popup_findpreview()* --- 307,315 ---- Get the |window-ID| for the popup info window, as it used by the popup menu. See |complete-popup|. The info popup is hidden when not used, it can be deleted with |popup_clear()| ! and |popup_close()|. Use |popup_show()| to reposition it to ! the item in the popup menu. ! Returns zero if there is none. popup_findpreview() *popup_findpreview()* *************** *** 314,320 **** Return zero if there is none. - popup_getoptions({id}) *popup_getoptions()* Return the {options} for popup {id} in a Dict. A zero value means the option was not set. For "zindex" the --- 317,322 ---- *************** *** 362,368 **** core_height height of the text box in screen cells firstline line of the buffer at top (1 unless scrolled) (not the value of the "firstline" property) ! lastline line of the buffer at the bottom scrollbar non-zero if a scrollbar is displayed visible one if the popup is displayed, zero if hidden Note that these are the actual screen positions. They differ --- 364,371 ---- core_height height of the text box in screen cells firstline line of the buffer at top (1 unless scrolled) (not the value of the "firstline" property) ! lastline line of the buffer at the bottom (updated when ! the popup is redrawn) scrollbar non-zero if a scrollbar is displayed visible one if the popup is displayed, zero if hidden Note that these are the actual screen positions. They differ *************** *** 566,571 **** --- 569,579 ---- Alternatively "center" can be used to position the popup in the center of the Vim window, in which case "line" and "col" are ignored. + posinvert When FALSE the value of "pos" is always used. When + TRUE (the default) and the popup does not fit + vertically and there is more space on the other side + then the popup is placed on the other side of the + position indicated by "line". textprop When present the popup is positioned next to a text property with this name and will move when the text property moves. Use an empty string to remove. See *************** *** 686,691 **** --- 694,701 ---- - [{lnum}, {start}, {end}]: if the cursor moved away from line {lnum}, before column {start} or after {end} + - [0, 0, 0] do not close the popup when the cursor + moves The popup also closes if the cursor moves to another line or to another window. mousemoved Like "moved" but referring to the mouse pointer *************** *** 752,773 **** These steps are needed to make this work: - Define a text property type, it defines the name. > ! call prop_type_add('popupMarker', {}) - Place a text property at the desired text: > let lnum = {line of the text} let col = {start column of the text} let len = {length of the text} let propId = {arbitrary but unique number} ! call prop_add(lnum, col, #{ \ length: len, \ type: 'popupMarker', \ id: propId, \ }) - Create a popup: > ! let winid = popup_create('the text', #{ ! \ pos: 'botleft', \ textprop: 'popupMarker', \ textpropid: propId, \ border: [], --- 762,783 ---- These steps are needed to make this work: - Define a text property type, it defines the name. > ! call prop_type_add('popupMarker', {}) - Place a text property at the desired text: > let lnum = {line of the text} let col = {start column of the text} let len = {length of the text} let propId = {arbitrary but unique number} ! call prop_add(lnum, col, #{ \ length: len, \ type: 'popupMarker', \ id: propId, \ }) - Create a popup: > ! let winid = popup_create('the text', #{ ! \ pos: 'botleft', \ textprop: 'popupMarker', \ textpropid: propId, \ border: [], *************** *** 807,813 **** a click, as in the example above, helps for that. - If the text property is removed the popup is closed. Use something like this: > ! call prop_remove(#{type: 'popupMarker', id: propId}) POPUP FILTER *popup-filter* --- 817,823 ---- a click, as in the example above, helps for that. - If the text property is removed the popup is closed. Use something like this: > ! call prop_remove(#{type: 'popupMarker', id: propId}) POPUP FILTER *popup-filter* *************** *** 852,860 **** cursor keys select another entry Tab accept current suggestion ! A mouse click arrives as . The coordinates are in ! v:mouse_popup_col and v:mouse_popup_row. The top-left screen cell of the ! popup is col 1, row 1 (not counting the border). Vim provides standard filters |popup_filter_menu()| and |popup_filter_yesno()|. --- 862,870 ---- cursor keys select another entry Tab accept current suggestion ! A mouse click arrives as . The coordinates are in |v:mouse_col| ! and |v:mouse_lnum|. The top-left screen cell of the popup is col 1, row 1 ! (not counting the border). Vim provides standard filters |popup_filter_menu()| and |popup_filter_yesno()|. *** ../vim-8.1.2272/src/structs.h 2019-11-02 22:54:37.409188799 +0100 --- src/structs.h 2019-11-09 14:46:27.121513517 +0100 *************** *** 2113,2119 **** POPPOS_TOPLEFT, POPPOS_BOTRIGHT, POPPOS_TOPRIGHT, ! POPPOS_CENTER } poppos_T; typedef enum { --- 2113,2120 ---- POPPOS_TOPLEFT, POPPOS_BOTRIGHT, POPPOS_TOPRIGHT, ! POPPOS_CENTER, ! POPPOS_NONE } poppos_T; typedef enum { *** ../vim-8.1.2272/src/popupwin.c 2019-11-06 21:09:13.668099304 +0100 --- src/popupwin.c 2019-11-09 15:19:05.374444654 +0100 *************** *** 390,395 **** --- 390,414 ---- } #endif + static poppos_T + get_pos_entry(dict_T *d, int give_error) + { + char_u *str = dict_get_string(d, (char_u *)"pos", FALSE); + int nr; + + if (str == NULL) + return POPPOS_NONE; + + for (nr = 0; nr < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T)); + ++nr) + if (STRCMP(str, poppos_entries[nr].pp_name) == 0) + return poppos_entries[nr].pp_val; + + if (give_error) + semsg(_(e_invarg2), str); + return POPPOS_NONE; + } + /* * Shared between popup_create() and f_popup_move(). */ *************** *** 420,439 **** if (di != NULL) wp->w_popup_fixed = dict_get_number(d, (char_u *)"fixed") != 0; - str = dict_get_string(d, (char_u *)"pos", FALSE); - if (str != NULL) { ! for (nr = 0; ! nr < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T)); ! ++nr) ! if (STRCMP(str, poppos_entries[nr].pp_name) == 0) ! { ! wp->w_popup_pos = poppos_entries[nr].pp_val; ! nr = -1; ! break; ! } ! if (nr != -1) ! semsg(_(e_invarg2), str); } str = dict_get_string(d, (char_u *)"textprop", FALSE); --- 439,449 ---- if (di != NULL) wp->w_popup_fixed = dict_get_number(d, (char_u *)"fixed") != 0; { ! poppos_T ppt = get_pos_entry(d, TRUE); ! ! if (ppt != POPPOS_NONE) ! wp->w_popup_pos = ppt; } str = dict_get_string(d, (char_u *)"textprop", FALSE); *************** *** 512,517 **** --- 522,529 ---- else wp->w_popup_lnum = nr; li = li->li_next; + if (nr == 0) + wp->w_popup_curwin = NULL; } mincol = tv_get_number(&li->li_tv); *************** *** 1634,1647 **** * Keep at least "width" columns from the right of the screen. */ void ! popup_set_wantpos_cursor(win_T *wp, int width) { setcursor_mayforce(TRUE); ! wp->w_wantline = curwin->w_winrow + curwin->w_wrow; ! if (wp->w_wantline == 0) // cursor in first line { ! wp->w_wantline = 2; ! wp->w_popup_pos = POPPOS_TOPLEFT; } wp->w_wantcol = curwin->w_wincol + curwin->w_wcol + 1; --- 1646,1672 ---- * Keep at least "width" columns from the right of the screen. */ void ! popup_set_wantpos_cursor(win_T *wp, int width, dict_T *d) { + poppos_T ppt = POPPOS_NONE; + + if (d != NULL) + ppt = get_pos_entry(d, FALSE); + setcursor_mayforce(TRUE); ! if (ppt == POPPOS_TOPRIGHT || ppt == POPPOS_TOPLEFT) { ! wp->w_wantline = curwin->w_winrow + curwin->w_wrow + 2; ! } ! else ! { ! wp->w_wantline = curwin->w_winrow + curwin->w_wrow; ! if (wp->w_wantline == 0) // cursor in first line ! { ! wp->w_wantline = 2; ! wp->w_popup_pos = ppt == POPPOS_BOTRIGHT ! ? POPPOS_TOPRIGHT : POPPOS_TOPLEFT; ! } } wp->w_wantcol = curwin->w_wincol + curwin->w_wcol + 1; *************** *** 1651,1656 **** --- 1676,1682 ---- if (wp->w_wantcol < 1) wp->w_wantcol = 1; } + popup_adjust_position(wp); } *************** *** 1834,1840 **** } if (type == TYPE_ATCURSOR) { ! popup_set_wantpos_cursor(wp, 0); set_moved_values(wp); set_moved_columns(wp, FIND_STRING); } --- 1860,1866 ---- } if (type == TYPE_ATCURSOR) { ! popup_set_wantpos_cursor(wp, 0, d); set_moved_values(wp); set_moved_columns(wp, FIND_STRING); } *************** *** 1935,1941 **** for (i = 0; i < 4; ++i) wp->w_popup_border[i] = 1; parse_previewpopup(wp); ! popup_set_wantpos_cursor(wp, wp->w_minwidth); } # ifdef FEAT_QUICKFIX if (type == TYPE_INFO) --- 1961,1967 ---- for (i = 0; i < 4; ++i) wp->w_popup_border[i] = 1; parse_previewpopup(wp); ! popup_set_wantpos_cursor(wp, wp->w_minwidth, d); } # ifdef FEAT_QUICKFIX if (type == TYPE_INFO) *** ../vim-8.1.2272/src/proto/popupwin.pro 2019-10-20 18:17:08.363431719 +0200 --- src/proto/popupwin.pro 2019-11-09 14:58:05.858137101 +0100 *************** *** 12,18 **** int popup_extra_width(win_T *wp); int parse_previewpopup(win_T *wp); int parse_completepopup(win_T *wp); ! void popup_set_wantpos_cursor(win_T *wp, int width); void popup_set_wantpos_rowcol(win_T *wp, int row, int col); void f_popup_clear(typval_T *argvars, typval_T *rettv); void f_popup_create(typval_T *argvars, typval_T *rettv); --- 12,18 ---- int popup_extra_width(win_T *wp); int parse_previewpopup(win_T *wp); int parse_completepopup(win_T *wp); ! void popup_set_wantpos_cursor(win_T *wp, int width, dict_T *d); void popup_set_wantpos_rowcol(win_T *wp, int row, int col); void f_popup_clear(typval_T *argvars, typval_T *rettv); void f_popup_create(typval_T *argvars, typval_T *rettv); *** ../vim-8.1.2272/src/ex_cmds.c 2019-10-31 04:38:31.353833447 +0100 --- src/ex_cmds.c 2019-11-09 14:58:21.458065896 +0100 *************** *** 4960,4966 **** { wp = popup_find_preview_window(); if (wp != NULL) ! popup_set_wantpos_cursor(wp, wp->w_minwidth); } else if (use_popup != USEPOPUP_NONE) { --- 4960,4966 ---- { wp = popup_find_preview_window(); if (wp != NULL) ! popup_set_wantpos_cursor(wp, wp->w_minwidth, NULL); } else if (use_popup != USEPOPUP_NONE) { *** ../vim-8.1.2272/src/testdir/test_popupwin.vim 2019-11-06 21:09:13.672099289 +0100 --- src/testdir/test_popupwin.vim 2019-11-09 15:24:34.300526762 +0100 *************** *** 1294,1299 **** --- 1294,1335 ---- bwipe! endfunc + func Test_popup_atcursor_pos() + CheckScreendump + + let lines =<< trim END + call setline(1, repeat([repeat('-', 60)], 15)) + set so=0 + + normal 9G3|r# + let winid1 = popup_atcursor(['first', 'second'], #{ + \ moved: [0, 0, 0], + \ }) + normal 9G21|r& + let winid1 = popup_atcursor(['FIrsT', 'SEcoND'], #{ + \ pos: 'botright', + \ moved: [0, 0, 0], + \ }) + normal 3G27|r% + let winid1 = popup_atcursor(['fiRSt', 'seCOnd'], #{ + \ pos: 'topleft', + \ moved: [0, 0, 0], + \ }) + normal 3G45|r@ + let winid1 = popup_atcursor(['First', 'SeconD'], #{ + \ pos: 'topright', + \ moved: [0, 0, 0], + \ }) + END + call writefile(lines, 'XtestPopupAtcursorPos') + let buf = RunVimInTerminal('-S XtestPopupAtcursorPos', #{rows: 12}) + call VerifyScreenDump(buf, 'Test_popupwin_atcursor_pos', {}) + + " clean up + call StopVimInTerminal(buf) + call delete('XtestPopupAtcursorPos') + endfunc + func Test_popup_beval() CheckScreendump CheckFeature balloon_eval_term *** ../vim-8.1.2272/src/testdir/dumps/Test_popupwin_atcursor_pos.dump 2019-11-09 15:31:57.958151715 +0100 --- src/testdir/dumps/Test_popupwin_atcursor_pos.dump 2019-11-09 15:24:42.464481343 +0100 *************** *** 0 **** --- 1,12 ---- + |-+0&#ffffff0@59| @14 + |-@59| @14 + |-@25|%|-@16>@|-@14| @14 + |-@25|f+0#0000001#ffd7ff255|i|R|S|t| |-+0#0000000#ffffff0@6|F+0#0000001#ffd7ff255|i|r|s|t| |-+0#0000000#ffffff0@14| @14 + |-@25|s+0#0000001#ffd7ff255|e|C|O|n|d|-+0#0000000#ffffff0@6|S+0#0000001#ffd7ff255|e|c|o|n|D|-+0#0000000#ffffff0@14| @14 + |-@59| @14 + |-@1|f+0#0000001#ffd7ff255|i|r|s|t| |-+0#0000000#ffffff0@6|F+0#0000001#ffd7ff255|I|r|s|T| |-+0#0000000#ffffff0@38| @14 + |-@1|s+0#0000001#ffd7ff255|e|c|o|n|d|-+0#0000000#ffffff0@6|S+0#0000001#ffd7ff255|E|c|o|N|D|-+0#0000000#ffffff0@38| @14 + |-@1|#|-@16|&|-@38| @14 + |-@59| @14 + |-@59| @14 + @57|3|,|4|5| @9|T|o|p| *** ../vim-8.1.2272/src/version.c 2019-11-08 23:00:22.086870727 +0100 --- src/version.c 2019-11-09 14:44:01.506298203 +0100 *************** *** 743,744 **** --- 743,746 ---- { /* Add new patch number below this line */ + /**/ + 2273, /**/ -- hundred-and-one symptoms of being an internet addict: 45. You buy a Captain Kirk chair with a built-in keyboard and mouse. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///