Skip to content

Commit 8a63529

Browse files
glepnirchrisbra
authored andcommitted
patch 9.1.1230: inconsistent CTRL-C behaviour for popup windows
Problem: Ctrl-C closes popup windows that have a filter callback, but does not close popups without a filter callback. Solution: Modified popup_do_filter() to also close popups without filter callback when Ctrl-C is pressed (glepnir). fixes: #16839 closes: #16928 Signed-off-by: glepnir <glephunter@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 9712a25 commit 8a63529

5 files changed

Lines changed: 38 additions & 2 deletions

File tree

runtime/doc/pattern.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*pattern.txt* For Vim version 9.1. Last change: 2024 Dec 26
1+
*pattern.txt* For Vim version 9.1. Last change: 2025 Mar 21
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -141,6 +141,7 @@ CTRL-C Interrupt current (search) command. Use CTRL-Break on
141141
help users who use "vim file | grep word" and don't
142142
know how to get out (blindly typing :qa<CR> would
143143
work).
144+
If a popup is open, the active popup will be closed.
144145

145146
*:noh* *:nohlsearch*
146147
:noh[lsearch] Stop the highlighting for the 'hlsearch' option. It

runtime/doc/version9.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*version9.txt* For Vim version 9.1. Last change: 2025 Mar 19
1+
*version9.txt* For Vim version 9.1. Last change: 2025 Mar 21
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -41653,6 +41653,7 @@ Others: ~
4165341653
- add |dist#vim9#Launch()| and |dist#vim9#Open()| to the |vim-script-library|
4165441654
and decouple it from |netrw|
4165541655
- new digraph "APPROACHES THE LIMIT" using ".="
41656+
- |CTRL-C| always closes the active |popup-window|.
4165641657

4165741658
*added-9.2*
4165841659
Added ~

src/popupwin.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3586,6 +3586,20 @@ popup_do_filter(int c)
35863586
&& (wp->w_filter_mode & state) != 0)
35873587
res = invoke_popup_filter(wp, c);
35883588

3589+
// when Ctrl-C and no popup has been processed (res is still FALSE)
3590+
// Try to find and close a popup that has no filter callback
3591+
if (c == Ctrl_C && res == FALSE)
3592+
{
3593+
popup_reset_handled(POPUP_HANDLED_2);
3594+
wp = find_next_popup(FALSE, POPUP_HANDLED_2);
3595+
if (wp != NULL)
3596+
{
3597+
popup_close_with_retval(wp, -1);
3598+
res = TRUE;
3599+
}
3600+
}
3601+
3602+
35893603
if (must_redraw > was_must_redraw)
35903604
{
35913605
int save_got_int = got_int;

src/testdir/test_popupwin.vim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3898,6 +3898,24 @@ func Test_popupwin_cancel()
38983898
call assert_equal({}, popup_getpos(win3))
38993899
endfunc
39003900

3901+
func Test_popupwin_cancel_with_without_filter()
3902+
let win1 = popup_create('with filter', #{line: 5, filter: {... -> 0}})
3903+
let win2 = popup_create('no filter', #{line: 10})
3904+
3905+
call assert_equal(5, popup_getpos(win1).line)
3906+
call assert_equal(10, popup_getpos(win2).line)
3907+
3908+
call feedkeys("\<C-C>", 'xt')
3909+
call assert_equal({}, popup_getpos(win1))
3910+
call assert_equal(10, popup_getpos(win2).line)
3911+
3912+
call feedkeys("\<C-C>", 'xt')
3913+
call assert_equal({}, popup_getpos(win1))
3914+
call assert_equal({}, popup_getpos(win2))
3915+
3916+
call popup_clear()
3917+
endfunc
3918+
39013919
func Test_popupwin_filter_redraw()
39023920
" Create two popups with a filter that closes the popup when typing "0".
39033921
" Both popups should close, even though the redraw also calls

src/version.c

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

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1230,
707709
/**/
708710
1229,
709711
/**/

0 commit comments

Comments
 (0)