]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0050: WM_SETFOCUS not handled immediately v9.2.0050
authorMuraoka Taro <koron.kaoriya@gmail.com>
Tue, 24 Feb 2026 21:30:43 +0000 (21:30 +0000)
committerChristian Brabandt <cb@256bit.org>
Tue, 24 Feb 2026 21:30:43 +0000 (21:30 +0000)
Problem:  In gvim on Windows, a certain problem can occur when the
          WM_SETFOCUS event sent after an external command is not
          processed immediately.
Solution: After posting WM_SETFOCUS, run the message loop to process it
          as quickly as possible (Muraoka Taro).

The problem is that Test_normal11_showcmd may fail when running the
test_normal.vim test.  Investigation revealed that the trigger was an
external command executed in the previous test,
Test_mouse_shape_after_failed_change, when two tests were executed
consecutively.  In gvim on Windows, a WM_SETFOCUS event will be sent
when an external command finishes executing.  This WM_SETFOCUS event is
not processed immediately, but rather by redraw, which is expected to
update showcmd. Because it is queued in typebuf at this time,
clear_showcmd(), which expects typebuf to be empty, cannot update
showcmd.

Also added a test that simulates the above problem.

closes: #19167

Signed-off-by: Muraoka Taro <koron.kaoriya@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/os_win32.c
src/testdir/test_normal.vim
src/version.c

index edaf7cb306ed9c7e61bef5d7afc96e18c0f79810..6ccd185f089b5aedc8bcbd11d33c37ae7f6ebb40 100644 (file)
@@ -4881,6 +4881,10 @@ mch_system_classic(char *cmd, int options)
 
     // Try to get input focus back.  Doesn't always work though.
     PostMessage(hwnd, WM_SETFOCUS, 0, 0);
+    // To increase the chances that WM_SETFOCUS will work, run the message loop
+    // here.  In addition, it prevents problems caused by delayed WM_SETFOCUS
+    // processing.
+    gui_mch_update();
 
     return ret;
 }
index 58c1b97832ee19fa9c5eafe34b629e2b056d8751..f41ae0552ca01f29de46cba8c4e87a973fa1f22c 100644 (file)
@@ -4411,4 +4411,33 @@ func Test_pos_percentage_in_turkish_locale()
   endtry
 endfunc
 
+" This test simulates the problem with gvim on Windows, observed when
+" Test_normal11_showcmd in test_normal.vim is executed consecutively after
+" Test_mouse_shape_after_failed_change.
+"
+" The problem occurred because WM_SETFOCUS was processed slowly, and typebuf
+" was not empty when it should have been.
+func Test_win32_gui_setfocus_prevent_showcmd()
+  if !has('win32') || !has('gui_running')
+    throw 'Skipped: Windows GUI regression test'
+  endif
+
+  " WM_SETFOCUS event occurs when finish to execute filter command in gvim
+  exe 'silent !echo foo'
+
+  set showcmd
+  10new
+  call setline(1, ['aaaaa', 'bbbbb', 'ccccc'])
+  call feedkeys("ggl\<C-V>lljj", 'xt')
+
+  " showcmd could not be updated because events originating from WM_SETFOCUS
+  " were stored in typebuf at here.  clear_showcmd() executed from redraw,
+  " will not draw the selection information unless you are in visual mode and
+  " typebuf is empty.
+  redraw!
+
+  call assert_match('3x3$', Screenline(&lines))
+  call feedkeys("\<C-V>", 'xt')
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab nofoldenable
index 620e1a5bd904710a08ef70a98a3d0ad5e6230f9d..076063b4cfc6f736c6008efeff779b63f95a0771 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    50,
 /**/
     49,
 /**/