patch 9.1.1351: Return value of getcmdline() inconsistent in CmdlineLeavePre

Commit: 
https://github.com/vim/vim/commit/92403697746a3ebaeb4ad267da2c7eb9c0e7b0bb
Author: zeertzjq <zeert...@outlook.com>
Date:   Mon Apr 28 18:04:00 2025 +0200

    patch 9.1.1351: Return value of getcmdline() inconsistent in CmdlineLeavePre
    
    Problem:  Return value of getcmdline() inconsistent in CmdlineLeavePre
              when leaving cmdline in different ways (after v9.1.1329).
    Solution: Trigger CmdlineLeavePre before calling abandon_cmdline() so
              that getcmdline() can return the command line (zeertzjq).
    
    closes: #17218
    
    Signed-off-by: zeertzjq <zeert...@outlook.com>
    Signed-off-by: Girish Palya <giris...@gmail.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/ex_getln.c b/src/ex_getln.c
index 24ff7a908..bbfe1e593 100644
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -2560,6 +2560,9 @@ cmdline_changed:
     }
 
 returncmd:
+    // Trigger CmdlineLeavePre autocommands if not already triggered.
+    if (!event_cmdlineleavepre_triggered)
+       trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINELEAVEPRE);
 
 #ifdef FEAT_RIGHTLEFT
     cmdmsg_rl = FALSE;
@@ -2616,10 +2619,6 @@ returncmd:
     if (some_key_typed)
        need_wait_return = FALSE;
 
-    // Trigger CmdlineLeavePre autocommands if not already triggered.
-    if (!event_cmdlineleavepre_triggered)
-       trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINELEAVEPRE);
-
     // Trigger CmdlineLeave autocommands.
     trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINELEAVE);
 
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index ae69dd62a..a2e365d23 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -2066,11 +2066,28 @@ func Test_Cmdline_Trigger()
   call assert_equal('CmdlineLeavePre', g:log)
   call assert_equal('CmdlineLeave', g:log2)
 
-  let g:count = 0
-  autocmd CmdlineLeavePre * let g:count += 1
-  call feedkeys(":let c = input('? ')\<cr>B\<cr>", "tx")
-  call assert_equal(2, g:count)
-  unlet! g:count
+  autocmd CmdlineLeavePre * let g:cmdline += [getcmdline()]
+
+  for end_keys in ["\<CR>", "\<NL>", "\<kEnter>", "\<C-C>", "\<Esc>",
+                 \ "\<C-\>\<C-N>", "\<C-\>\<C-G>"]
+    let g:cmdline = []
+    let g:log = ''
+    let g:log2 = ''
+    call assert_equal('', g:log)
+    let keys = $':echo "hello"{end_keys}'
+    let msg = keytrans(keys)
+    call feedkeys(keys, "tx")
+    call assert_equal(['echo "hello"'], g:cmdline, msg)
+    call assert_equal('CmdlineLeavePre', g:log, msg)
+    call assert_equal('CmdlineLeave', g:log2, msg)
+  endfor
+
+  let g:cmdline = []
+  call feedkeys(":let c = input('? ')\<cr>ABCDE\<cr>", "tx")
+  call assert_equal(["let c = input('? ')", 'ABCDE'], g:cmdline)
+
+  au! CmdlineLeavePre
+  unlet! g:cmdline
   unlet! g:log
   unlet! g:log2
   bw!
diff --git a/src/version.c b/src/version.c
index a18ffced7..ac424bca3 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1351,
 /**/
     1350,
 /**/

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1u9R8L-00DMIf-JA%40256bit.org.

Raspunde prin e-mail lui