From a89b9750ee8875a349a2a2e53983faa007a7de73 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 29 Mar 2026 22:29:58 +0800 Subject: [PATCH] vim-patch:9.2.0050: WM_SETFOCUS not handled immediately 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: vim/vim#19167 https://github.com/vim/vim/commit/c4a6fa3eade9d30e0bda7e5b7077951da9e75279 Co-authored-by: Muraoka Taro --- test/old/testdir/test_normal.vim | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/old/testdir/test_normal.vim b/test/old/testdir/test_normal.vim index a371769b03..7513c2fe16 100644 --- a/test/old/testdir/test_normal.vim +++ b/test/old/testdir/test_normal.vim @@ -4441,4 +4441,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\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("\", 'xt') +endfunc + " vim: shiftwidth=2 sts=2 expandtab nofoldenable