Commit: patch 9.2.0967: hit-enter prompt eats keys from a running mapping

Christian Brabandt <[email protected]>
Newsgroups gmane.editors.vim.devel
Message-ID <[email protected]>
patch 9.2.0967: hit-enter prompt eats keys from a running mapping

Commit: https://github.com/vim/vim/commit/6025ea9e029b0681df37ee19e0d3992fb7f4d7fd
Author: XiaowenHu96 <[email protected]>
Date:   Mon Aug 17 21:01:37 2026 +0000

    patch 9.2.0967: hit-enter prompt eats keys from a running mapping
    
    Problem:  The hit-enter prompt fires whenever a message scrolls the screen.
              When this happens while a mapping is being processed, it consumes
              the mapping's next key, causing unexpected behavior for users.
    Solution: Similar to what 9.1.1969 did for stuffed characters, skip the
              hit-enter prompt when there are still keys pending from a mapping
              in the typeahead buffer.
    
    related: neovim/neovim#38298
    related: neovim/neovim#20635
    related: neovim/neovim#30890
    closes:  #20753
    
    AI assisted.
    
    Signed-off-by: XiaowenHu96 <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/message.c b/src/message.c
index de56ddcb9..1eecb053a 100644
--- a/src/message.c
+++ b/src/message.c
@@ -1287,10 +1287,12 @@ wait_return(int redraw)
 	c = CAR;		// no need for a return in ex mode
 	got_int = FALSE;
     }
-    else if (!stuff_empty())
-	// When there are stuffed characters, the next stuffed character will
-	// dismiss the hit-enter prompt immediately and have to be put back, so
-	// instead just don't show the hit-enter prompt at all.
+    else if (!stuff_empty() || !typebuf_typed())
+	// When there are stuffed characters or pending mapped characters, the
+	// next character will dismiss the hit-enter prompt immediately.  A
+	// stuffed character then has to be put back, while a mapped character
+	// may even be swallowed (e.g. "g" treated as a message-scrollback key),
+	// so instead just don't show the hit-enter prompt at all.
 	c = CAR;
     else
     {
diff --git a/src/testdir/test_messages.vim b/src/testdir/test_messages.vim
index 2e5a16e4b..b628a28e8 100644
--- a/src/testdir/test_messages.vim
+++ b/src/testdir/test_messages.vim
@@ -813,6 +813,33 @@ func Test_long_formatprg_no_hit_enter()
   call StopVimInTerminal(buf)
 endfunc
 
+" A message shown while a mapping is still being processed must not raise a
+" hit-enter prompt that eats the mapping's remaining keys.
+func Test_hit_enter_no_eat_mapped_keys()
+  CheckRunVimInTerminal
+
+  let lines =<< trim END
+    set ruler
+    call setline(1, range(1, 20))
+    " The 8-line :echo scrolls the screen and would raise a hit-enter prompt;
+    " the mapping then runs "gg" to move the cursor to line 1.
+    nnoremap X :echo "a
b
c
d
e
f
g
h"<CR>gg
+    normal! 10G
+  END
+  call writefile(lines, 'XtestHitEnterMap', 'D')
+  let buf = RunVimInTerminal('-S XtestHitEnterMap', #{rows: 10})
+  call WaitForAssert({-> assert_match('10,1', term_getline(buf, 10))})
+
+  call term_sendkeys(buf, "X")
+  " Without the fix the hit-enter prompt eats the mapping's "g" keys and the
+  " cursor stays put.  With the fix "gg" runs and moves the cursor to line 1.
+  call WaitForAssert({-> assert_match('1,1', term_getline(buf, 10))})
+  call assert_notmatch('Press ENTER', term_getline(buf, 10))
+
+  " clean up
+  call StopVimInTerminal(buf)
+endfunc
+
 " Test that fileinfo is shown after deleting the last listed buffer with :bd
 func Test_fileinfo_after_last_bd()
   CheckRunVimInTerminal
diff --git a/src/version.c b/src/version.c
index c387ee67a..047699420 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 */
+/**/
+    967,
 /**/
     966,
 /**/

-- 
-- 
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/E1ww4fh-0095H9-Ei%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.