• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Révisione5ef5d820b5bea54365de705700112ea9ecdd3dc (tree)
l'heure2019-11-09 23:45:04
AuteurBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Message de Log

patch 8.1.2273: wrong default when "pos" is changed with popup_atcursor()

Commit: https://github.com/vim/vim/commit/4dd8fe0b4f49ec267640fb457672452825b11df0
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Nov 9 15:33:31 2019 +0100

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
                1. (#5151)

Change Summary

Modification

diff -r 6b3126903e2e -r e5ef5d820b5b runtime/doc/popup.txt
--- a/runtime/doc/popup.txt Fri Nov 08 23:15:03 2019 +0100
+++ b/runtime/doc/popup.txt Sat Nov 09 15:45:04 2019 +0100
@@ -1,4 +1,4 @@
1-*popup.txt* For Vim version 8.1. Last change: 2019 Nov 03
1+*popup.txt* For Vim version 8.1. Last change: 2019 Nov 09
22
33
44 VIM REFERENCE MANUAL by Bram Moolenaar
@@ -186,6 +186,8 @@
186186 \ moved: 'WORD',
187187 \ })
188188 < Use {options} to change the properties.
189+ If "pos" is passed as "topleft" then the default for "line"
190+ becomes "cursor+1".
189191
190192 Can also be used as a |method|: >
191193 GetText()->popup_atcursor({})
@@ -362,7 +364,8 @@
362364 core_height height of the text box in screen cells
363365 firstline line of the buffer at top (1 unless scrolled)
364366 (not the value of the "firstline" property)
365- lastline line of the buffer at the bottom
367+ lastline line of the buffer at the bottom (updated when
368+ the popup is redrawn)
366369 scrollbar non-zero if a scrollbar is displayed
367370 visible one if the popup is displayed, zero if hidden
368371 Note that these are the actual screen positions. They differ
@@ -566,6 +569,11 @@
566569 Alternatively "center" can be used to position the
567570 popup in the center of the Vim window, in which case
568571 "line" and "col" are ignored.
572+ posinvert When FALSE the value of "pos" is always used. When
573+ TRUE (the default) and the popup does not fit
574+ vertically and there is more space on the other side
575+ then the popup is placed on the other side of the
576+ position indicated by "line".
569577 textprop When present the popup is positioned next to a text
570578 property with this name and will move when the text
571579 property moves. Use an empty string to remove. See
@@ -686,6 +694,8 @@
686694 - [{lnum}, {start}, {end}]: if the cursor moved away
687695 from line {lnum}, before column {start} or after
688696 {end}
697+ - [0, 0, 0] do not close the popup when the cursor
698+ moves
689699 The popup also closes if the cursor moves to another
690700 line or to another window.
691701 mousemoved Like "moved" but referring to the mouse pointer
@@ -852,9 +862,9 @@
852862 cursor keys select another entry
853863 Tab accept current suggestion
854864
855-A mouse click arrives as <LeftMouse>. The coordinates are in
856-v:mouse_popup_col and v:mouse_popup_row. The top-left screen cell of the
857-popup is col 1, row 1 (not counting the border).
865+A mouse click arrives as <LeftMouse>. The coordinates are in |v:mouse_col|
866+and |v:mouse_lnum|. The top-left screen cell of the popup is col 1, row 1
867+(not counting the border).
858868
859869 Vim provides standard filters |popup_filter_menu()| and
860870 |popup_filter_yesno()|.
diff -r 6b3126903e2e -r e5ef5d820b5b src/ex_cmds.c
--- a/src/ex_cmds.c Fri Nov 08 23:15:03 2019 +0100
+++ b/src/ex_cmds.c Sat Nov 09 15:45:04 2019 +0100
@@ -4960,7 +4960,7 @@
49604960 {
49614961 wp = popup_find_preview_window();
49624962 if (wp != NULL)
4963- popup_set_wantpos_cursor(wp, wp->w_minwidth);
4963+ popup_set_wantpos_cursor(wp, wp->w_minwidth, NULL);
49644964 }
49654965 else if (use_popup != USEPOPUP_NONE)
49664966 {
diff -r 6b3126903e2e -r e5ef5d820b5b src/popupwin.c
--- a/src/popupwin.c Fri Nov 08 23:15:03 2019 +0100
+++ b/src/popupwin.c Sat Nov 09 15:45:04 2019 +0100
@@ -390,6 +390,25 @@
390390 }
391391 #endif
392392
393+ static poppos_T
394+get_pos_entry(dict_T *d, int give_error)
395+{
396+ char_u *str = dict_get_string(d, (char_u *)"pos", FALSE);
397+ int nr;
398+
399+ if (str == NULL)
400+ return POPPOS_NONE;
401+
402+ for (nr = 0; nr < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T));
403+ ++nr)
404+ if (STRCMP(str, poppos_entries[nr].pp_name) == 0)
405+ return poppos_entries[nr].pp_val;
406+
407+ if (give_error)
408+ semsg(_(e_invarg2), str);
409+ return POPPOS_NONE;
410+}
411+
393412 /*
394413 * Shared between popup_create() and f_popup_move().
395414 */
@@ -420,20 +439,11 @@
420439 if (di != NULL)
421440 wp->w_popup_fixed = dict_get_number(d, (char_u *)"fixed") != 0;
422441
423- str = dict_get_string(d, (char_u *)"pos", FALSE);
424- if (str != NULL)
425442 {
426- for (nr = 0;
427- nr < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T));
428- ++nr)
429- if (STRCMP(str, poppos_entries[nr].pp_name) == 0)
430- {
431- wp->w_popup_pos = poppos_entries[nr].pp_val;
432- nr = -1;
433- break;
434- }
435- if (nr != -1)
436- semsg(_(e_invarg2), str);
443+ poppos_T ppt = get_pos_entry(d, TRUE);
444+
445+ if (ppt != POPPOS_NONE)
446+ wp->w_popup_pos = ppt;
437447 }
438448
439449 str = dict_get_string(d, (char_u *)"textprop", FALSE);
@@ -512,6 +522,8 @@
512522 else
513523 wp->w_popup_lnum = nr;
514524 li = li->li_next;
525+ if (nr == 0)
526+ wp->w_popup_curwin = NULL;
515527 }
516528
517529 mincol = tv_get_number(&li->li_tv);
@@ -1634,14 +1646,27 @@
16341646 * Keep at least "width" columns from the right of the screen.
16351647 */
16361648 void
1637-popup_set_wantpos_cursor(win_T *wp, int width)
1649+popup_set_wantpos_cursor(win_T *wp, int width, dict_T *d)
16381650 {
1651+ poppos_T ppt = POPPOS_NONE;
1652+
1653+ if (d != NULL)
1654+ ppt = get_pos_entry(d, FALSE);
1655+
16391656 setcursor_mayforce(TRUE);
1640- wp->w_wantline = curwin->w_winrow + curwin->w_wrow;
1641- if (wp->w_wantline == 0) // cursor in first line
1657+ if (ppt == POPPOS_TOPRIGHT || ppt == POPPOS_TOPLEFT)
16421658 {
1643- wp->w_wantline = 2;
1644- wp->w_popup_pos = POPPOS_TOPLEFT;
1659+ wp->w_wantline = curwin->w_winrow + curwin->w_wrow + 2;
1660+ }
1661+ else
1662+ {
1663+ wp->w_wantline = curwin->w_winrow + curwin->w_wrow;
1664+ if (wp->w_wantline == 0) // cursor in first line
1665+ {
1666+ wp->w_wantline = 2;
1667+ wp->w_popup_pos = ppt == POPPOS_BOTRIGHT
1668+ ? POPPOS_TOPRIGHT : POPPOS_TOPLEFT;
1669+ }
16451670 }
16461671
16471672 wp->w_wantcol = curwin->w_wincol + curwin->w_wcol + 1;
@@ -1651,6 +1676,7 @@
16511676 if (wp->w_wantcol < 1)
16521677 wp->w_wantcol = 1;
16531678 }
1679+
16541680 popup_adjust_position(wp);
16551681 }
16561682
@@ -1834,7 +1860,7 @@
18341860 }
18351861 if (type == TYPE_ATCURSOR)
18361862 {
1837- popup_set_wantpos_cursor(wp, 0);
1863+ popup_set_wantpos_cursor(wp, 0, d);
18381864 set_moved_values(wp);
18391865 set_moved_columns(wp, FIND_STRING);
18401866 }
@@ -1935,7 +1961,7 @@
19351961 for (i = 0; i < 4; ++i)
19361962 wp->w_popup_border[i] = 1;
19371963 parse_previewpopup(wp);
1938- popup_set_wantpos_cursor(wp, wp->w_minwidth);
1964+ popup_set_wantpos_cursor(wp, wp->w_minwidth, d);
19391965 }
19401966 # ifdef FEAT_QUICKFIX
19411967 if (type == TYPE_INFO)
diff -r 6b3126903e2e -r e5ef5d820b5b src/proto/popupwin.pro
--- a/src/proto/popupwin.pro Fri Nov 08 23:15:03 2019 +0100
+++ b/src/proto/popupwin.pro Sat Nov 09 15:45:04 2019 +0100
@@ -12,7 +12,7 @@
1212 int popup_extra_width(win_T *wp);
1313 int parse_previewpopup(win_T *wp);
1414 int parse_completepopup(win_T *wp);
15-void popup_set_wantpos_cursor(win_T *wp, int width);
15+void popup_set_wantpos_cursor(win_T *wp, int width, dict_T *d);
1616 void popup_set_wantpos_rowcol(win_T *wp, int row, int col);
1717 void f_popup_clear(typval_T *argvars, typval_T *rettv);
1818 void f_popup_create(typval_T *argvars, typval_T *rettv);
diff -r 6b3126903e2e -r e5ef5d820b5b src/structs.h
--- a/src/structs.h Fri Nov 08 23:15:03 2019 +0100
+++ b/src/structs.h Sat Nov 09 15:45:04 2019 +0100
@@ -2113,7 +2113,8 @@
21132113 POPPOS_TOPLEFT,
21142114 POPPOS_BOTRIGHT,
21152115 POPPOS_TOPRIGHT,
2116- POPPOS_CENTER
2116+ POPPOS_CENTER,
2117+ POPPOS_NONE
21172118 } poppos_T;
21182119
21192120 typedef enum {
diff -r 6b3126903e2e -r e5ef5d820b5b src/testdir/dumps/Test_popupwin_atcursor_pos.dump
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/testdir/dumps/Test_popupwin_atcursor_pos.dump Sat Nov 09 15:45:04 2019 +0100
@@ -0,0 +1,12 @@
1+|-+0&#ffffff0@59| @14
2+|-@59| @14
3+|-@25|%|-@16>@|-@14| @14
4+|-@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
5+|-@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
6+|-@59| @14
7+|-@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
8+|-@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
9+|-@1|#|-@16|&|-@38| @14
10+|-@59| @14
11+|-@59| @14
12+@57|3|,|4|5| @9|T|o|p|
diff -r 6b3126903e2e -r e5ef5d820b5b src/testdir/test_popupwin.vim
--- a/src/testdir/test_popupwin.vim Fri Nov 08 23:15:03 2019 +0100
+++ b/src/testdir/test_popupwin.vim Sat Nov 09 15:45:04 2019 +0100
@@ -1294,6 +1294,42 @@
12941294 bwipe!
12951295 endfunc
12961296
1297+func Test_popup_atcursor_pos()
1298+ CheckScreendump
1299+
1300+ let lines =<< trim END
1301+ call setline(1, repeat([repeat('-', 60)], 15))
1302+ set so=0
1303+
1304+ normal 9G3|r#
1305+ let winid1 = popup_atcursor(['first', 'second'], #{
1306+ \ moved: [0, 0, 0],
1307+ \ })
1308+ normal 9G21|r&
1309+ let winid1 = popup_atcursor(['FIrsT', 'SEcoND'], #{
1310+ \ pos: 'botright',
1311+ \ moved: [0, 0, 0],
1312+ \ })
1313+ normal 3G27|r%
1314+ let winid1 = popup_atcursor(['fiRSt', 'seCOnd'], #{
1315+ \ pos: 'topleft',
1316+ \ moved: [0, 0, 0],
1317+ \ })
1318+ normal 3G45|r@
1319+ let winid1 = popup_atcursor(['First', 'SeconD'], #{
1320+ \ pos: 'topright',
1321+ \ moved: [0, 0, 0],
1322+ \ })
1323+ END
1324+ call writefile(lines, 'XtestPopupAtcursorPos')
1325+ let buf = RunVimInTerminal('-S XtestPopupAtcursorPos', #{rows: 12})
1326+ call VerifyScreenDump(buf, 'Test_popupwin_atcursor_pos', {})
1327+
1328+ " clean up
1329+ call StopVimInTerminal(buf)
1330+ call delete('XtestPopupAtcursorPos')
1331+endfunc
1332+
12971333 func Test_popup_beval()
12981334 CheckScreendump
12991335 CheckFeature balloon_eval_term
diff -r 6b3126903e2e -r e5ef5d820b5b src/version.c
--- a/src/version.c Fri Nov 08 23:15:03 2019 +0100
+++ b/src/version.c Sat Nov 09 15:45:04 2019 +0100
@@ -742,6 +742,8 @@
742742 static int included_patches[] =
743743 { /* Add new patch number below this line */
744744 /**/
745+ 2273,
746+/**/
745747 2272,
746748 /**/
747749 2271,
Afficher sur ancien navigateur de dépôt.