Commit: patch 9.2.0992: popup filter gets the key at the hit-enter prompt

Christian Brabandt <[email protected]>
Newsgroups gmane.editors.vim.devel
Message-ID <[email protected]>
patch 9.2.0992: popup filter gets the key at the hit-enter prompt

Commit: https://github.com/vim/vim/commit/2af3a6e151a9df5c3bce077e8a994f5bc79ec258
Author: Hirohito Higashi <[email protected]>
Date:   Thu Aug 20 21:26:07 2026 +0000

    patch 9.2.0992: popup filter gets the key at the hit-enter prompt
    
    Problem:  When a popup with a filter is displayed and a message causes the
              hit-enter prompt, the key goes to the popup filter instead of the
              prompt.  The closed popup then stays on the screen, since there is
              no redraw while the prompt is up.
    Solution: Do not invoke popup filters while Vim is waiting for a key at a
              prompt of its own.  Adjust Test_popup_filter_win_execute_error(),
              which relied on the filter getting the key at the prompt
              (Hirohito Higashi).
    
    fixes:   #21052
    closes:  #21068
    related: #6999
    
    Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
    Signed-off-by: Hirohito Higashi <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/popupwin.c b/src/popupwin.c
index cbfe72f97..d44e845ee 100644
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -5847,6 +5847,13 @@ popup_do_filter(int c)
 	return FALSE;
 #endif
 
+    // Vim is waiting for a key at a prompt of its own, the key is not meant
+    // for a popup filter. MODE_HITRETURN includes MODE_NORMAL, thus the
+    // filter mode check below would match.
+    if (State == MODE_HITRETURN || State == MODE_ASKMORE
+	    || State == MODE_CONFIRM || State == MODE_EXTERNCMD)
+	return FALSE;
+
     if (recursive)
 	return FALSE;
     recursive = TRUE;
diff --git a/src/testdir/dumps/Test_popupwin_hit_enter_1.dump b/src/testdir/dumps/Test_popupwin_hit_enter_1.dump
new file mode 100644
index 000000000..34e2c11d5
--- /dev/null
+++ b/src/testdir/dumps/Test_popupwin_hit_enter_1.dump
@@ -0,0 +1,15 @@
+|4+0&#ffffff0| @73
+|5| @73
+|6| @73
+|7| @73
+|8| @2|o+0#0000001#ffd7ff255|n|e| +0#0000000#ffffff0@67
+|9| @73
+|1|0| @72
+|1@1| @72
+|1|2| @72
+|1|3| @72
+|1|4| @72
+|x@74
+@75
+| @74
+|P+0#00e0003&|r|e|s@1| |E|N|T|E|R| |o|r| |t|y|p|e| |c|o|m@1|a|n|d| |t|o| |c|o|n|t|i|n|u|e> +0#0000000&@35
diff --git a/src/testdir/dumps/Test_popupwin_hit_enter_2.dump b/src/testdir/dumps/Test_popupwin_hit_enter_2.dump
new file mode 100644
index 000000000..535cc2b00
--- /dev/null
+++ b/src/testdir/dumps/Test_popupwin_hit_enter_2.dump
@@ -0,0 +1,15 @@
+>1+0&#ffffff0| @73
+|2| @73
+|3| @73
+|4| @73
+|5| @73
+|6| @73
+|7| @73
+|8| @2|o+0#0000001#ffd7ff255|n|e| +0#0000000#ffffff0@67
+|9| @73
+|1|0| @72
+|1@1| @72
+|1|2| @72
+|1|3| @72
+|1|4| @72
+@57|1|,|1| @10|T|o|p| 
diff --git a/src/testdir/dumps/Test_popupwin_win_execute.dump b/src/testdir/dumps/Test_popupwin_win_execute.dump
index b890a28a6..d2d31c7d6 100644
--- a/src/testdir/dumps/Test_popupwin_win_execute.dump
+++ b/src/testdir/dumps/Test_popupwin_win_execute.dump
@@ -2,9 +2,9 @@
 |~+0#4040ff13&| @73
 |~| @73
 |~| @73
-|~| @31|s+0#0000001#ffd7ff255|o|m|e| |t|e|x|t| +0#4040ff13#ffffff0@32
 |~| @73
 |~| @73
 |~| @73
 |~| @73
-| +0#0000000&@56|0|,|0|-|1| @8|A|l@1| 
+|~| @73
+|E+0#ffffff16#e000002|1@1|7|:| |U|n|k|n|o|w|n| |f|u|n|c|t|i|o|n|:| |i|n|v|a|l|i|d|f|i|l|t|e|r| +0#0000000#ffffff0@19|0|,|0|-|1| @8|A|l@1| 
diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim
index e751d82dc..4ee44ffba 100644
--- a/src/testdir/test_popupwin.vim
+++ b/src/testdir/test_popupwin.vim
@@ -1786,11 +1786,12 @@ func Test_popup_filter_win_execute_error()
   call writefile(lines, 'XtestPopupWinExecuteError', 'D')
   let buf = RunVimInTerminal('-S XtestPopupWinExecuteError', #{rows: 10, wait_for_ruler: 0})
 
+  " The CR is consumed by the hit-enter prompt, the key after it reaches the
+  " popup filter.
   call WaitFor({-> term_getline(buf, 9) =~ 'Not an editor command: invalidCommand'})
   call term_sendkeys(buf, "\<CR>")
-  call WaitFor({-> term_getline(buf, 9) =~ 'Unknown function: invalidfilter'})
-  call term_sendkeys(buf, "\<CR>")
-  call WaitFor({-> term_getline(buf, 9) =~ 'Not allowed in a popup window'})
+  call term_sendkeys(buf, "x")
+  call WaitFor({-> term_getline(buf, 10) =~ 'Unknown function: invalidfilter'})
   call term_sendkeys(buf, "\<CR>")
   call term_sendkeys(buf, "\<CR>")
   call VerifyScreenDump(buf, 'Test_popupwin_win_execute', {})
@@ -6283,4 +6284,33 @@ func Test_popupwin_textprop_redraw()
   call StopVimInTerminal(buf)
 endfunc
 
+func Test_popup_no_filter_at_hit_enter()
+  CheckScreendump
+
+  let lines =<< trim END
+      call setline(1, range(1, 20))
+      func MyFilter(id, key)
+        call popup_close(a:id)
+        return 1
+      endfunc
+      func ShowPopup()
+        call popup_create(['one'], #{line: 8, col: 5, filter: 'MyFilter'})
+        redraw
+        echomsg repeat('x', &columns * 2)
+      endfunc
+      nnoremap <F3> <Cmd>call ShowPopup()<CR>
+  END
+  call writefile(lines, 'XtestPopupHitEnter', 'D')
+  let buf = RunVimInTerminal('-S XtestPopupHitEnter', #{rows: 15})
+  call term_sendkeys(buf, "\<F3>")
+  call VerifyScreenDump(buf, 'Test_popupwin_hit_enter_1', {})
+
+  " The key goes to the hit-enter prompt, not to the popup filter, thus the
+  " popup is still there.
+  call term_sendkeys(buf, "\<CR>")
+  call VerifyScreenDump(buf, 'Test_popupwin_hit_enter_2', {})
+
+  call StopVimInTerminal(buf)
+endfunc
+
 " vim: shiftwidth=2 sts=2
diff --git a/src/version.c b/src/version.c
index 494d36f01..efbbd9cc6 100644
--- a/src/version.c
+++ b/src/version.c
@@ -763,6 +763,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    992,
 /**/
     991,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1wxAKx-00E7Qe-3S%40256bit.org.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.