Skip to content

Commit 7964873

Browse files
committed
patch 8.1.1714: cannot preview a file in a popup window
Problem: Cannot preview a file in a popup window. Solution: Add the 'previewpopup' option.
1 parent df9c6ca commit 7964873

12 files changed

Lines changed: 320 additions & 67 deletions

runtime/doc/options.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5627,7 +5627,16 @@ A jump table for the options with a short description can be found at |Q_op|.
56275627
{not available when compiled without the |+windows| or
56285628
|+quickfix| features}
56295629
Default height for a preview window. Used for |:ptag| and associated
5630-
commands. Used for |CTRL-W_}| when no count is given.
5630+
commands. Used for |CTRL-W_}| when no count is given. Not used when
5631+
'previewpopup' is set.
5632+
5633+
*'previewpopup'* *'pvp'*
5634+
'previewpopup' 'pvp' string (default empty)
5635+
global
5636+
{not available when compiled without the |+windows|,
5637+
|+textprop| or |+quickfix| feature}
5638+
When not empty a popup window is used for commands that would open a
5639+
preview window. See |preview-popup|.
56315640

56325641
*'previewwindow'* *'nopreviewwindow'*
56335642
*'pvw'* *'nopvw'* *E590*

runtime/doc/windows.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,15 @@ height of the preview window when it's opened. The 'previewwindow' option is
864864
set in the preview window to be able to recognize it. The 'winfixheight'
865865
option is set to have it keep the same height when opening/closing other
866866
windows.
867-
867+
*preview-popup*
868+
Alternatively, a popup window can be used by setting the 'previewpopup'
869+
option. When set, it overrules the 'previewwindow' and 'previewheight'
870+
settings. The option is a comma separated list of values:
871+
height maximum height of the popup
872+
width maximu width of the popup
873+
Example: >
874+
:set previewpopup=height:10,width:60
875+
<
868876
*:pta* *:ptag*
869877
:pta[g][!] [tagname]
870878
Does ":tag[!] [tagname]" and shows the found tag in a

src/ex_cmds.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6270,28 +6270,42 @@ prepare_tagpreview(
62706270
*/
62716271
if (!curwin->w_p_pvw)
62726272
{
6273-
FOR_ALL_WINDOWS(wp)
6274-
if (wp->w_p_pvw)
6275-
break;
6273+
# ifdef FEAT_TEXT_PROP
6274+
if (*p_pvp != NUL)
6275+
{
6276+
wp = popup_find_preview_window();
6277+
if (wp != NULL)
6278+
popup_set_wantpos(wp);
6279+
}
6280+
else
6281+
# endif
6282+
{
6283+
FOR_ALL_WINDOWS(wp)
6284+
if (wp->w_p_pvw)
6285+
break;
6286+
}
62766287
if (wp != NULL)
62776288
win_enter(wp, undo_sync);
62786289
else
62796290
{
62806291
/*
62816292
* There is no preview window open yet. Create one.
62826293
*/
6283-
if (win_split(g_do_tagpreview > 0 ? g_do_tagpreview : 0, 0)
6284-
== FAIL)
6294+
# ifdef FEAT_TEXT_PROP
6295+
if (*p_pvp != NUL)
6296+
return popup_create_preview_window();
6297+
# endif
6298+
if (win_split(g_do_tagpreview > 0 ? g_do_tagpreview : 0, 0) == FAIL)
62856299
return FALSE;
62866300
curwin->w_p_pvw = TRUE;
62876301
curwin->w_p_wfh = TRUE;
6288-
RESET_BINDING(curwin); /* don't take over 'scrollbind'
6289-
and 'cursorbind' */
6302+
RESET_BINDING(curwin); // don't take over 'scrollbind'
6303+
// and 'cursorbind'
62906304
# ifdef FEAT_DIFF
6291-
curwin->w_p_diff = FALSE; /* no 'diff' */
6305+
curwin->w_p_diff = FALSE; // no 'diff'
62926306
# endif
62936307
# ifdef FEAT_FOLDING
6294-
curwin->w_p_fdc = 0; /* no 'foldcolumn' */
6308+
curwin->w_p_fdc = 0; // no 'foldcolumn'
62956309
# endif
62966310
return TRUE;
62976311
}

src/ex_docmd.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5893,12 +5893,17 @@ ex_pclose(exarg_T *eap)
58935893
{
58945894
win_T *win;
58955895

5896+
// First close any normal window.
58965897
FOR_ALL_WINDOWS(win)
58975898
if (win->w_p_pvw)
58985899
{
58995900
ex_win_close(eap->forceit, win, NULL);
5900-
break;
5901+
return;
59015902
}
5903+
# ifdef FEAT_TEXT_PROP
5904+
// Also when 'previewpopup' is empty, it might have been cleared.
5905+
popup_close_preview();
5906+
# endif
59025907
}
59035908
#endif
59045909

src/option.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,6 +2079,15 @@ static struct vimoption options[] =
20792079
(char_u *)NULL, PV_NONE,
20802080
#endif
20812081
{(char_u *)12L, (char_u *)0L} SCTX_INIT},
2082+
{"previewpopup", "pvp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2083+
#ifdef FEAT_TEXT_PROP
2084+
(char_u *)&p_pvp, PV_NONE,
2085+
{(char_u *)"", (char_u *)0L}
2086+
#else
2087+
(char_u *)NULL, PV_NONE,
2088+
{(char_u *)NULL, (char_u *)0L}
2089+
#endif
2090+
SCTX_INIT},
20822091
{"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
20832092
#if defined(FEAT_QUICKFIX)
20842093
(char_u *)VAR_WIN, PV_PVW,
@@ -7831,6 +7840,15 @@ did_set_string_option(
78317840
}
78327841
#endif
78337842

7843+
#ifdef FEAT_TEXT_PROP
7844+
// 'previewpopup'
7845+
else if (varp == &p_pvp)
7846+
{
7847+
if (parse_previewpopup(NULL) == FAIL)
7848+
errmsg = e_invarg;
7849+
}
7850+
#endif
7851+
78347852
/* Options that are a list of flags. */
78357853
else
78367854
{

src/option.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,9 @@ EXTERN char_u *p_fp; /* 'formatprg' */
499499
EXTERN int p_fs; /* 'fsync' */
500500
#endif
501501
EXTERN int p_gd; /* 'gdefault' */
502+
#ifdef FEAT_TEXT_PROP
503+
EXTERN char_u *p_pvp; // 'previewpopup'
504+
#endif
502505
#ifdef FEAT_PRINTER
503506
EXTERN char_u *p_pdev; /* 'printdevice' */
504507
# ifdef FEAT_POSTSCRIPT

0 commit comments

Comments
 (0)