From 4dd8fe0b4f49ec267640fb457672452825b11df0 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 9 Nov 2019 15:33:31 +0100 Subject: patch 8.1.2273: wrong default when "pos" is changed with popup_atcursor() 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) --- src/ex_cmds.c | 2 +- src/popupwin.c | 66 ++++++++++++++++------- src/proto/popupwin.pro | 2 +- src/structs.h | 3 +- src/testdir/dumps/Test_popupwin_atcursor_pos.dump | 12 +++++ src/testdir/test_popupwin.vim | 36 +++++++++++++ src/version.c | 2 + 7 files changed, 100 insertions(+), 23 deletions(-) create mode 100644 src/testdir/dumps/Test_popupwin_atcursor_pos.dump (limited to 'src') diff --git a/src/ex_cmds.c b/src/ex_cmds.c index a7f80a80a8..db5fecd5b7 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -4960,7 +4960,7 @@ prepare_tagpreview( { wp = popup_find_preview_window(); if (wp != NULL) - popup_set_wantpos_cursor(wp, wp->w_minwidth); + popup_set_wantpos_cursor(wp, wp->w_minwidth, NULL); } else if (use_popup != USEPOPUP_NONE) { diff --git a/src/popupwin.c b/src/popupwin.c index a6e2e8726b..ac8fff3d63 100644 --- a/src/popupwin.c +++ b/src/popupwin.c @@ -390,6 +390,25 @@ popup_add_timeout(win_T *wp, int time) } #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,20 +439,11 @@ apply_move_options(win_T *wp, dict_T *d) 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); + 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,6 +522,8 @@ handle_moved_argument(win_T *wp, dictitem_T *di, int mousemoved) 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,14 +1646,27 @@ parse_completepopup(win_T *wp) * Keep at least "width" columns from the right of the screen. */ void -popup_set_wantpos_cursor(win_T *wp, int width) +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); - wp->w_wantline = curwin->w_winrow + curwin->w_wrow; - if (wp->w_wantline == 0) // cursor in first line + if (ppt == POPPOS_TOPRIGHT || ppt == POPPOS_TOPLEFT) { - wp->w_wantline = 2; - wp->w_popup_pos = 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,6 +1676,7 @@ popup_set_wantpos_cursor(win_T *wp, int width) if (wp->w_wantcol < 1) wp->w_wantcol = 1; } + popup_adjust_position(wp); } @@ -1834,7 +1860,7 @@ popup_create(typval_T *argvars, typval_T *rettv, create_type_T type) } if (type == TYPE_ATCURSOR) { - popup_set_wantpos_cursor(wp, 0); + popup_set_wantpos_cursor(wp, 0, d); set_moved_values(wp); set_moved_columns(wp, FIND_STRING); } @@ -1935,7 +1961,7 @@ popup_create(typval_T *argvars, typval_T *rettv, create_type_T type) for (i = 0; i < 4; ++i) wp->w_popup_border[i] = 1; parse_previewpopup(wp); - popup_set_wantpos_cursor(wp, wp->w_minwidth); + popup_set_wantpos_cursor(wp, wp->w_minwidth, d); } # ifdef FEAT_QUICKFIX if (type == TYPE_INFO) diff --git a/src/proto/popupwin.pro b/src/proto/popupwin.pro index 4ec4a748de..bc4315a812 100644 --- a/src/proto/popupwin.pro +++ b/src/proto/popupwin.pro @@ -12,7 +12,7 @@ int popup_width(win_T *wp); 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_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); diff --git a/src/structs.h b/src/structs.h index 124b059738..fd3a1d072b 100644 --- a/src/structs.h +++ b/src/structs.h @@ -2113,7 +2113,8 @@ typedef enum { POPPOS_TOPLEFT, POPPOS_BOTRIGHT, POPPOS_TOPRIGHT, - POPPOS_CENTER + POPPOS_CENTER, + POPPOS_NONE } poppos_T; typedef enum { diff --git a/src/testdir/dumps/Test_popupwin_atcursor_pos.dump b/src/testdir/dumps/Test_popupwin_atcursor_pos.dump new file mode 100644 index 0000000000..a42b6e6ff5 --- /dev/null +++ b/src/testdir/dumps/Test_popupwin_atcursor_pos.dump @@ -0,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| diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim index eab569fa9d..52d5add328 100644 --- a/src/testdir/test_popupwin.vim +++ b/src/testdir/test_popupwin.vim @@ -1294,6 +1294,42 @@ func Test_popup_atcursor() 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 diff --git a/src/version.c b/src/version.c index 77b3a8a48e..6b6d661bcd 100644 --- a/src/version.c +++ b/src/version.c @@ -741,6 +741,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 2273, /**/ 2272, /**/ -- cgit v1.2.3