Skip to content

Commit 815b76b

Browse files
committed
patch 8.1.1438: some commands cause trouble in a popup window
Problem: Some commands cause trouble in a popup window. Solution: Add NOT_IN_POPUP_WINDOW.
1 parent 3a97bb3 commit 815b76b

8 files changed

Lines changed: 70 additions & 4 deletions

File tree

src/ex_cmds2.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,6 +1864,8 @@ do_argfile(exarg_T *eap, int argn)
18641864
char_u *p;
18651865
int old_arg_idx = curwin->w_arg_idx;
18661866

1867+
if (NOT_IN_POPUP_WINDOW)
1868+
return;
18671869
if (argn < 0 || argn >= ARGCOUNT)
18681870
{
18691871
if (ARGCOUNT <= 1)

src/ex_docmd.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5452,6 +5452,8 @@ ex_doautocmd(exarg_T *eap)
54525452
static void
54535453
ex_bunload(exarg_T *eap)
54545454
{
5455+
if (NOT_IN_POPUP_WINDOW)
5456+
return;
54555457
eap->errmsg = do_bufdel(
54565458
eap->cmdidx == CMD_bdelete ? DOBUF_DEL
54575459
: eap->cmdidx == CMD_bwipeout ? DOBUF_WIPE
@@ -5466,6 +5468,8 @@ ex_bunload(exarg_T *eap)
54665468
static void
54675469
ex_buffer(exarg_T *eap)
54685470
{
5471+
if (NOT_IN_POPUP_WINDOW)
5472+
return;
54695473
if (*eap->arg)
54705474
eap->errmsg = e_trailing;
54715475
else
@@ -6768,6 +6772,9 @@ ex_splitview(exarg_T *eap)
67686772
|| eap->cmdidx == CMD_tabfind
67696773
|| eap->cmdidx == CMD_tabnew;
67706774

6775+
if (NOT_IN_POPUP_WINDOW)
6776+
return;
6777+
67716778
#ifdef FEAT_GUI
67726779
need_mouse_correct = TRUE;
67736780
#endif
@@ -6895,6 +6902,8 @@ ex_tabnext(exarg_T *eap)
68956902
{
68966903
int tab_number;
68976904

6905+
if (NOT_IN_POPUP_WINDOW)
6906+
return;
68986907
switch (eap->cmdidx)
68996908
{
69006909
case CMD_tabfirst:
@@ -7146,6 +7155,8 @@ do_exedit(
71467155
int need_hide;
71477156
int exmode_was = exmode_active;
71487157

7158+
if (NOT_IN_POPUP_WINDOW)
7159+
return;
71497160
/*
71507161
* ":vi" command ends Ex mode.
71517162
*/

src/macros.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,9 @@
339339

340340
/* Wether a command index indicates a user command. */
341341
#define IS_USER_CMDIDX(idx) ((int)(idx) < 0)
342+
343+
#ifdef FEAT_TEXT_PROP
344+
# define NOT_IN_POPUP_WINDOW not_in_popup_window()
345+
#else
346+
# define NOT_IN_POPUP_WINDOW 0
347+
#endif

src/popupwin.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,4 +747,16 @@ f_popup_getoptions(typval_T *argvars, typval_T *rettv)
747747
# endif
748748
}
749749
}
750+
751+
int
752+
not_in_popup_window()
753+
{
754+
if (bt_popup(curwin->w_buffer))
755+
{
756+
emsg(_("E994: Not allowed in a popup window"));
757+
return TRUE;
758+
}
759+
return FALSE;
760+
}
761+
750762
#endif // FEAT_TEXT_PROP

src/proto/popupwin.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ void ex_popupclear(exarg_T *eap);
1313
void f_popup_move(typval_T *argvars, typval_T *rettv);
1414
void f_popup_getpos(typval_T *argvars, typval_T *rettv);
1515
void f_popup_getoptions(typval_T *argvars, typval_T *rettv);
16+
int not_in_popup_window(void);
1617
/* vim: set ft=c : */

src/testdir/test_popupwin.vim

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,27 @@ endfunc
108108
func Test_win_execute_closing_curwin()
109109
split
110110
let winid = popup_create('some text', {})
111-
call win_execute(winid, winnr() .. "close")
112-
call assert_equal(1, winnr())
111+
call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994')
112+
popupclear
113+
endfunc
114+
115+
func Test_win_execute_not_allowed()
116+
let winid = popup_create('some text', {})
117+
call assert_fails('call win_execute(winid, "split")', 'E994:')
118+
call assert_fails('call win_execute(winid, "vsplit")', 'E994:')
119+
call assert_fails('call win_execute(winid, "close")', 'E994:')
120+
call assert_fails('call win_execute(winid, "bdelete")', 'E994:')
121+
call assert_fails('call win_execute(winid, "tabnew")', 'E994:')
122+
call assert_fails('call win_execute(winid, "tabnext")', 'E994:')
123+
call assert_fails('call win_execute(winid, "next")', 'E994:')
124+
call assert_fails('call win_execute(winid, "rewind")', 'E994:')
125+
call assert_fails('call win_execute(winid, "buf")', 'E994:')
126+
call assert_fails('call win_execute(winid, "edit")', 'E994:')
127+
call assert_fails('call win_execute(winid, "enew")', 'E994:')
128+
call assert_fails('call win_execute(winid, "wincmd x")', 'E994:')
129+
call assert_fails('call win_execute(winid, "wincmd w")', 'E994:')
130+
call assert_fails('call win_execute(winid, "wincmd t")', 'E994:')
131+
call assert_fails('call win_execute(winid, "wincmd b")', 'E994:')
113132
popupclear
114133
endfunc
115134

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,8 @@ static char *(features[]) =
767767

768768
static int included_patches[] =
769769
{ /* Add new patch number below this line */
770+
/**/
771+
1438,
770772
/**/
771773
1437,
772774
/**/

src/window.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ do_window(
8787
#endif
8888
char_u cbuf[40];
8989

90-
Prenum1 = Prenum == 0 ? 1 : Prenum;
90+
if (NOT_IN_POPUP_WINDOW)
91+
return;
9192

9293
#ifdef FEAT_CMDWIN
9394
# define CHECK_CMDWIN \
@@ -102,6 +103,8 @@ do_window(
102103
# define CHECK_CMDWIN do { /**/ } while (0)
103104
#endif
104105

106+
Prenum1 = Prenum == 0 ? 1 : Prenum;
107+
105108
switch (nchar)
106109
{
107110
/* split current window in two parts, horizontally */
@@ -732,6 +735,9 @@ cmd_with_count(
732735
int
733736
win_split(int size, int flags)
734737
{
738+
if (NOT_IN_POPUP_WINDOW)
739+
return FAIL;
740+
735741
/* When the ":tab" modifier was used open a new tab page instead. */
736742
if (may_open_tabpage() == OK)
737743
return OK;
@@ -1509,7 +1515,9 @@ win_exchange(long Prenum)
15091515
win_T *wp2;
15101516
int temp;
15111517

1512-
if (ONE_WINDOW) /* just one window */
1518+
if (NOT_IN_POPUP_WINDOW)
1519+
return;
1520+
if (ONE_WINDOW) // just one window
15131521
{
15141522
beep_flush();
15151523
return;
@@ -2363,6 +2371,9 @@ win_close(win_T *win, int free_buf)
23632371
tabpage_T *prev_curtab = curtab;
23642372
frame_T *win_frame = win->w_frame->fr_parent;
23652373

2374+
if (NOT_IN_POPUP_WINDOW)
2375+
return FAIL;
2376+
23662377
if (last_window())
23672378
{
23682379
emsg(_("E444: Cannot close last window"));
@@ -4221,6 +4232,8 @@ win_goto(win_T *wp)
42214232
win_T *owp = curwin;
42224233
#endif
42234234

4235+
if (NOT_IN_POPUP_WINDOW)
4236+
return;
42244237
if (text_locked())
42254238
{
42264239
beep_flush();

0 commit comments

Comments
 (0)