Skip to content

Commit 576a4a6

Browse files
committed
patch 8.1.1880: cannot show extra info for completion in a popup window
Problem: Cannot show extra info for completion in a popup window. Solution: Add the "popup" entry in 'completeopt'.
1 parent 93cf85f commit 576a4a6

17 files changed

+310
-56
lines changed

runtime/doc/options.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*options.txt* For Vim version 8.1. Last change: 2019 Jul 31
1+
*options.txt* For Vim version 8.1. Last change: 2019 Aug 17
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1915,6 +1915,11 @@ A jump table for the options with a short description can be found at |Q_op|.
19151915
completion in the preview window. Only works in
19161916
combination with "menu" or "menuone".
19171917

1918+
popup Show extra information about the currently selected
1919+
completion in a popup window. Only works in combination
1920+
with "menu" or "menuone". Overrides "preview".
1921+
{only works when compiled with the +textprop feature}
1922+
19181923
noinsert Do not insert any text for a match until the user selects
19191924
a match from the menu. Only works in combination with
19201925
"menu" or "menuone". No effect if "longest" is present.
@@ -5650,6 +5655,8 @@ A jump table for the options with a short description can be found at |Q_op|.
56505655
|+textprop| or |+quickfix| feature}
56515656
When not empty a popup window is used for commands that would open a
56525657
preview window. See |preview-popup|.
5658+
Not used for the insert completion info, add "popup" to
5659+
'completeopt' for that.
56535660

56545661
*'previewwindow'* *'nopreviewwindow'*
56555662
*'pvw'* *'nopvw'* *E590*

src/ex_cmds.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5131,7 +5131,9 @@ free_old_sub(void)
51315131
*/
51325132
int
51335133
prepare_tagpreview(
5134-
int undo_sync) /* sync undo when leaving the window */
5134+
int undo_sync, // sync undo when leaving the window
5135+
int use_previewpopup, // use popup if 'previewpopup' set
5136+
int use_popup) // use other popup window
51355137
{
51365138
win_T *wp;
51375139

@@ -5145,11 +5147,16 @@ prepare_tagpreview(
51455147
if (!curwin->w_p_pvw)
51465148
{
51475149
# ifdef FEAT_TEXT_PROP
5148-
if (*p_pvp != NUL)
5150+
if (use_previewpopup && *p_pvp != NUL)
51495151
{
51505152
wp = popup_find_preview_window();
51515153
if (wp != NULL)
5152-
popup_set_wantpos(wp, wp->w_minwidth);
5154+
popup_set_wantpos_cursor(wp, wp->w_minwidth);
5155+
}
5156+
else if (use_popup)
5157+
{
5158+
wp = popup_find_info_window();
5159+
// TODO: set position
51535160
}
51545161
else
51555162
# endif
@@ -5166,8 +5173,8 @@ prepare_tagpreview(
51665173
* There is no preview window open yet. Create one.
51675174
*/
51685175
# ifdef FEAT_TEXT_PROP
5169-
if (*p_pvp != NUL)
5170-
return popup_create_preview_window();
5176+
if ((use_previewpopup && *p_pvp != NUL) || use_popup)
5177+
return popup_create_preview_window(use_popup);
51715178
# endif
51725179
if (win_split(g_do_tagpreview > 0 ? g_do_tagpreview : 0, 0) == FAIL)
51735180
return FALSE;

src/ex_docmd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5825,7 +5825,7 @@ ex_pclose(exarg_T *eap)
58255825
}
58265826
# ifdef FEAT_TEXT_PROP
58275827
// Also when 'previewpopup' is empty, it might have been cleared.
5828-
popup_close_preview();
5828+
popup_close_preview(FALSE);
58295829
# endif
58305830
}
58315831
#endif
@@ -8614,7 +8614,7 @@ ex_pedit(exarg_T *eap)
86148614

86158615
// Open the preview window or popup and make it the current window.
86168616
g_do_tagpreview = p_pvh;
8617-
prepare_tagpreview(TRUE);
8617+
prepare_tagpreview(TRUE, TRUE, FALSE);
86188618

86198619
// Edit the file.
86208620
do_exedit(eap, NULL);

src/option.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3247,7 +3247,7 @@ static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
32473247
static char *(p_fcl_values[]) = {"all", NULL};
32483248
#endif
32493249
#ifdef FEAT_INS_EXPAND
3250-
static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
3250+
static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "popup", "noinsert", "noselect", NULL};
32513251
# ifdef BACKSLASH_IN_FILENAME
32523252
static char *(p_csl_values[]) = {"slash", "backslash", NULL};
32533253
# endif

src/popupmnu.c

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,9 @@ pum_set_selected(int n, int repeat)
638638
{
639639
int resized = FALSE;
640640
int context = pum_height / 2;
641+
#ifdef FEAT_TEXT_PROP
642+
int has_info = FALSE;
643+
#endif
641644

642645
pum_selected = n;
643646

@@ -690,11 +693,14 @@ pum_set_selected(int n, int repeat)
690693
pum_first = pum_selected + context - pum_height + 1;
691694
}
692695
}
696+
// adjust for the number of lines displayed
697+
if (pum_first > pum_size - pum_height)
698+
pum_first = pum_size - pum_height;
693699

694700
#if defined(FEAT_QUICKFIX)
695701
/*
696702
* Show extra info in the preview window if there is something and
697-
* 'completeopt' contains "preview".
703+
* 'completeopt' contains "preview" or "popup".
698704
* Skip this when tried twice already.
699705
* Skip this also when there is not much room.
700706
* NOTE: Be very careful not to sync undo!
@@ -707,43 +713,71 @@ pum_set_selected(int n, int repeat)
707713
win_T *curwin_save = curwin;
708714
tabpage_T *curtab_save = curtab;
709715
int res = OK;
716+
# ifdef FEAT_TEXT_PROP
717+
int use_popup = strstr((char *)p_cot, "popup") != NULL;
718+
# else
719+
# define use_popup 0
720+
# endif
721+
has_info = TRUE;
710722

711-
/* Open a preview window. 3 lines by default. Prefer
712-
* 'previewheight' if set and smaller. */
723+
// Open a preview window. 3 lines by default. Prefer
724+
// 'previewheight' if set and smaller.
713725
g_do_tagpreview = 3;
714726
if (p_pvh > 0 && p_pvh < g_do_tagpreview)
715727
g_do_tagpreview = p_pvh;
716728
++RedrawingDisabled;
717-
/* Prevent undo sync here, if an autocommand syncs undo weird
718-
* things can happen to the undo tree. */
729+
// Prevent undo sync here, if an autocommand syncs undo weird
730+
// things can happen to the undo tree.
719731
++no_u_sync;
720-
resized = prepare_tagpreview(FALSE);
732+
resized = prepare_tagpreview(FALSE, FALSE, use_popup);
721733
--no_u_sync;
722734
--RedrawingDisabled;
723735
g_do_tagpreview = 0;
724736

725-
if (curwin->w_p_pvw)
737+
if (curwin->w_p_pvw
738+
# ifdef FEAT_TEXT_PROP
739+
|| (curwin->w_popup_flags & POPF_INFO)
740+
# endif
741+
)
726742
{
743+
# ifdef FEAT_TEXT_PROP
744+
if (use_popup)
745+
{
746+
int col = pum_col + pum_width + 1;
747+
748+
if (Columns - col < 20 && Columns - col < pum_col)
749+
{
750+
col = pum_col - 1;
751+
curwin->w_popup_pos = POPPOS_TOPRIGHT;
752+
curwin->w_maxwidth = pum_col - 1;
753+
}
754+
else
755+
curwin->w_maxwidth = Columns - col + 1;
756+
curwin->w_maxwidth -= popup_extra_width(curwin);
757+
popup_set_wantpos_rowcol(curwin,
758+
pum_row + pum_selected - pum_first, col);
759+
}
760+
# endif
727761
if (!resized
728762
&& curbuf->b_nwindows == 1
729763
&& curbuf->b_fname == NULL
730764
&& bt_nofile(curbuf)
731765
&& curbuf->b_p_bh[0] == 'w')
732766
{
733-
/* Already a "wipeout" buffer, make it empty. */
767+
// Already a "wipeout" buffer, make it empty.
734768
while (!BUFEMPTY())
735769
ml_delete((linenr_T)1, FALSE);
736770
}
737771
else
738772
{
739-
/* Don't want to sync undo in the current buffer. */
773+
// Don't want to sync undo in the current buffer.
740774
++no_u_sync;
741775
res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0, NULL);
742776
--no_u_sync;
743777
if (res == OK)
744778
{
745-
/* Edit a new, empty buffer. Set options for a "wipeout"
746-
* buffer. */
779+
// Edit a new, empty buffer. Set options for a "wipeout"
780+
// buffer.
747781
set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL);
748782
set_option_value((char_u *)"bt", 0L,
749783
(char_u *)"nofile", OPT_LOCAL);
@@ -774,10 +808,12 @@ pum_set_selected(int n, int repeat)
774808
p = e + 1;
775809
}
776810
}
811+
// delete the empty last line
812+
ml_delete(curbuf->b_ml.ml_line_count, FALSE);
777813

778814
/* Increase the height of the preview window to show the
779815
* text, but no more than 'previewheight' lines. */
780-
if (repeat == 0)
816+
if (repeat == 0 && !use_popup)
781817
{
782818
if (lnum > p_pvh)
783819
lnum = p_pvh;
@@ -792,6 +828,8 @@ pum_set_selected(int n, int repeat)
792828
curbuf->b_p_ma = FALSE;
793829
curwin->w_cursor.lnum = 1;
794830
curwin->w_cursor.col = 0;
831+
if (use_popup && win_valid(curwin_save))
832+
redraw_win_later(curwin_save, SOME_VALID);
795833

796834
if ((curwin != curwin_save && win_valid(curwin_save))
797835
|| (curtab != curtab_save
@@ -852,6 +890,11 @@ pum_set_selected(int n, int repeat)
852890
}
853891
#endif
854892
}
893+
# ifdef FEAT_TEXT_PROP
894+
if (!has_info)
895+
// close any popup info window
896+
popup_close_preview(TRUE);
897+
# endif
855898

856899
if (!resized)
857900
pum_redraw();
@@ -869,6 +912,10 @@ pum_undisplay(void)
869912
redraw_all_later(NOT_VALID);
870913
redraw_tabline = TRUE;
871914
status_redraw_all();
915+
#ifdef FEAT_TEXT_PROP
916+
// close any popup info window
917+
popup_close_preview(TRUE);
918+
#endif
872919
}
873920

874921
/*

0 commit comments

Comments
 (0)