Skip to content

Commit 934470e

Browse files
committed
patch 8.1.1963: popup window filter may be called recursively
Problem: Popup window filter may be called recursively when using a Normal mode command. Solution: Prevent recursiveness. (closes #4887) Also restore KeyTyped.
1 parent 55008aa commit 934470e

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/popupwin.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2764,8 +2764,14 @@ invoke_popup_filter(win_T *wp, int c)
27642764
int
27652765
popup_do_filter(int c)
27662766
{
2767+
static int recursive = FALSE;
27672768
int res = FALSE;
27682769
win_T *wp;
2770+
int save_KeyTyped = KeyTyped;
2771+
2772+
if (recursive)
2773+
return FALSE;
2774+
recursive = TRUE;
27692775

27702776
popup_reset_handled();
27712777

@@ -2776,13 +2782,15 @@ popup_do_filter(int c)
27762782

27772783
wp = mouse_find_win(&row, &col, FIND_POPUP);
27782784
if (wp != NULL && popup_close_if_on_X(wp, row, col))
2779-
return TRUE;
2785+
res = TRUE;
27802786
}
27812787

27822788
while (!res && (wp = find_next_popup(FALSE)) != NULL)
27832789
if (wp->w_filter_cb.cb_name != NULL)
27842790
res = invoke_popup_filter(wp, c);
27852791

2792+
recursive = FALSE;
2793+
KeyTyped = save_KeyTyped;
27862794
return res;
27872795
}
27882796

src/testdir/test_popupwin.vim

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,6 +1919,31 @@ func Test_popupwin_with_buffer()
19191919
call delete('XsomeFile')
19201920
endfunc
19211921

1922+
func Test_popupwin_with_buffer_and_filter()
1923+
new Xwithfilter
1924+
call setline(1, range(100))
1925+
let bufnr = bufnr()
1926+
hide
1927+
1928+
func BufferFilter(win, key)
1929+
if a:key == 'G'
1930+
" recursive use of "G" does not cause problems.
1931+
call win_execute(a:win, 'normal! G')
1932+
return 1
1933+
endif
1934+
return 0
1935+
endfunc
1936+
1937+
let winid = popup_create(bufnr, #{maxheight: 5, filter: 'BufferFilter'})
1938+
call assert_equal(1, popup_getpos(winid).firstline)
1939+
redraw
1940+
call feedkeys("G", 'xt')
1941+
call assert_equal(99, popup_getpos(winid).firstline)
1942+
1943+
call popup_close(winid)
1944+
exe 'bwipe! ' .. bufnr
1945+
endfunc
1946+
19221947
func Test_popupwin_width()
19231948
let winid = popup_create(repeat(['short', 'long long long line', 'medium width'], 50), #{
19241949
\ maxwidth: 40,

src/version.c

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

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1963,
764766
/**/
765767
1962,
766768
/**/

0 commit comments

Comments
 (0)