From ef77598bfba1cd588f6b310d1806b725b8bec9cb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 14 Jan 2023 19:29:55 +0800 Subject: vim-patch:8.2.4346: a custom statusline may cause Esc to work like Enter Problem: A custom statusline may cause Esc to work like Enter on the command line when the popup menu is displayed. Solution: Save and restore KeyTyped. (closes vim/vim#9749) https://github.com/vim/vim/commit/481acb11413a436653e235d2098990b2ad47d195 Co-authored-by: Bram Moolenaar --- src/nvim/statusline.c | 4 ++++ src/nvim/testdir/test_cmdline.vim | 15 +++++++++++++++ 2 files changed, 19 insertions(+) (limited to 'src') diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c index 7647c1fcfb..4f1453a815 100644 --- a/src/nvim/statusline.c +++ b/src/nvim/statusline.c @@ -639,6 +639,7 @@ int fillchar_status(int *attr, win_T *wp) void redraw_custom_statusline(win_T *wp) { static bool entered = false; + bool saved_KeyTyped = KeyTyped; // When called recursively return. This can happen when the statusline // contains an expression that triggers a redraw. @@ -649,6 +650,9 @@ void redraw_custom_statusline(win_T *wp) win_redr_custom(wp, false, false); entered = false; + + // A user function may reset KeyTyped, restore it. + KeyTyped = saved_KeyTyped; } static void ui_ext_tabline_update(void) diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 2f4048cc33..68560d5d49 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -2304,6 +2304,14 @@ func Test_wildmenu_pum() return repeat(['aaaa'], 120) endfunc command -nargs=* -complete=customlist,CmdCompl Tcmd + + func MyStatusLine() abort + return 'status' + endfunc + func SetupStatusline() + set statusline=%!MyStatusLine() + set laststatus=2 + endfunc [CODE] call writefile(commands, 'Xtest') @@ -2487,6 +2495,13 @@ func Test_wildmenu_pum() call term_sendkeys(buf, ":ls\") call term_sendkeys(buf, ":com\ ") call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {}) + call term_sendkeys(buf, "\\") + + " Esc still works to abort the command when 'statusline' is set + call term_sendkeys(buf, ":call SetupStatusline()\") + call term_sendkeys(buf, ":si\") + call term_sendkeys(buf, "\") + call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {}) call term_sendkeys(buf, "\\") call StopVimInTerminal(buf) -- cgit From 81473c8ab241286aafe8724d173df2c6b692e119 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 14 Jan 2023 19:31:11 +0800 Subject: vim-patch:8.2.4382: a custom 'tabline' may cause Esc to work like Enter Problem: A custom 'tabline' may cause Esc to work like Enter on the command line when the popup menu is displayed. Solution: Save and restore KeyTyped. (closes vim/vim#9776) https://github.com/vim/vim/commit/e4835bf34001471a102528659af009bc46361141 Co-authored-by: Bram Moolenaar --- src/nvim/statusline.c | 8 ++++---- src/nvim/testdir/test_cmdline.vim | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c index 4f1453a815..ca157ba697 100644 --- a/src/nvim/statusline.c +++ b/src/nvim/statusline.c @@ -268,6 +268,7 @@ static void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler) StlClickRecord *tabtab; win_T *ewp; int p_crb_save; + bool save_KeyTyped = KeyTyped; bool is_stl_global = global_stl_height() > 0; ScreenGrid *grid = &default_grid; @@ -422,6 +423,9 @@ static void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler) theend: entered = false; + + // A user function may reset KeyTyped, restore it. + KeyTyped = save_KeyTyped; } void win_redr_winbar(win_T *wp) @@ -639,7 +643,6 @@ int fillchar_status(int *attr, win_T *wp) void redraw_custom_statusline(win_T *wp) { static bool entered = false; - bool saved_KeyTyped = KeyTyped; // When called recursively return. This can happen when the statusline // contains an expression that triggers a redraw. @@ -650,9 +653,6 @@ void redraw_custom_statusline(win_T *wp) win_redr_custom(wp, false, false); entered = false; - - // A user function may reset KeyTyped, restore it. - KeyTyped = saved_KeyTyped; } static void ui_ext_tabline_update(void) diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 68560d5d49..8fc6e9847d 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -2312,6 +2312,15 @@ func Test_wildmenu_pum() set statusline=%!MyStatusLine() set laststatus=2 endfunc + + func MyTabLine() + return 'my tab line' + endfunc + func SetupTabline() + set statusline= + set tabline=%!MyTabLine() + set showtabline=2 + endfunc [CODE] call writefile(commands, 'Xtest') @@ -2503,6 +2512,12 @@ func Test_wildmenu_pum() call term_sendkeys(buf, "\") call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {}) + " Esc still works to abort the command when 'tabline' is set + call term_sendkeys(buf, ":call SetupTabline()\") + call term_sendkeys(buf, ":si\") + call term_sendkeys(buf, "\") + call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {}) + call term_sendkeys(buf, "\\") call StopVimInTerminal(buf) call delete('Xtest') -- cgit From f95ad61a8945b64a58750073e2cb2beb30767062 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 14 Jan 2023 19:32:12 +0800 Subject: vim-patch:8.2.4391: command line executed when typing Esc in the GUI Problem: Command line executed when typing Esc in the GUI. Solution: Move saving/restoring KeyTyped to build_stl_str_hl(). (closes vim/vim#9783) https://github.com/vim/vim/commit/0e1f36fc59b589e4755fd9102013971f45222084 Co-authored-by: Bram Moolenaar --- src/nvim/statusline.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c index ca157ba697..db3e3f91bf 100644 --- a/src/nvim/statusline.c +++ b/src/nvim/statusline.c @@ -268,7 +268,6 @@ static void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler) StlClickRecord *tabtab; win_T *ewp; int p_crb_save; - bool save_KeyTyped = KeyTyped; bool is_stl_global = global_stl_height() > 0; ScreenGrid *grid = &default_grid; @@ -423,9 +422,6 @@ static void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler) theend: entered = false; - - // A user function may reset KeyTyped, restore it. - KeyTyped = save_KeyTyped; } void win_redr_winbar(win_T *wp) @@ -948,6 +944,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n char *usefmt = fmt; const int save_must_redraw = must_redraw; const int save_redr_type = curwin->w_redr_type; + const bool save_KeyTyped = KeyTyped; // TODO(Bram): find out why using called_emsg_before makes tests fail, does it // matter? // const int called_emsg_before = called_emsg; @@ -2153,5 +2150,8 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n set_string_option_direct(opt_name, -1, "", OPT_FREE | opt_scope, SID_ERROR); } + // A user function may reset KeyTyped, restore it. + KeyTyped = save_KeyTyped; + return width; } -- cgit From d98e4e4b2ecd84162635a5f354dc4ddc6a49abc5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 14 Jan 2023 19:52:44 +0800 Subject: vim-patch:9.0.1195: restoring KeyTyped when building statusline not tested Problem: Restoring KeyTyped when building statusline not tested. Solution: Add a test. Clean up and fix other tests. (closes vim/vim#11815) https://github.com/vim/vim/commit/378e6c03f98efc88e8c2675e05a548f9bb7889a1 --- src/nvim/testdir/test_statusline.vim | 27 +++++++++++++++++++++++---- src/nvim/testdir/test_tabline.vim | 26 ++++++++++++++++++++++++-- src/nvim/testdir/test_window_cmd.vim | 6 ++++++ 3 files changed, 53 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_statusline.vim b/src/nvim/testdir/test_statusline.vim index 25ab1cf518..990c852ccd 100644 --- a/src/nvim/testdir/test_statusline.vim +++ b/src/nvim/testdir/test_statusline.vim @@ -569,22 +569,41 @@ func Test_statusline_showcmd() CheckScreendump let lines =<< trim END + func MyStatusLine() + return '%S' + endfunc + set laststatus=2 - set statusline=%S + set statusline=%!MyStatusLine() set showcmdloc=statusline call setline(1, ['a', 'b', 'c']) + set foldopen+=jump + 1,2fold + 3 END call writefile(lines, 'XTest_statusline', 'D') let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 6}) - call feedkeys("\Gl", "xt") + + call term_sendkeys(buf, "g") call VerifyScreenDump(buf, 'Test_statusline_showcmd_1', {}) - call feedkeys("\1234", "xt") + " typing "gg" should open the fold + call term_sendkeys(buf, "g") call VerifyScreenDump(buf, 'Test_statusline_showcmd_2', {}) - call feedkeys("\:set statusline=\:\1234", "xt") + call term_sendkeys(buf, "\Gl") call VerifyScreenDump(buf, 'Test_statusline_showcmd_3', {}) + + call term_sendkeys(buf, "\1234") + call VerifyScreenDump(buf, 'Test_statusline_showcmd_4', {}) + + call term_sendkeys(buf, "\:set statusline=\") + call term_sendkeys(buf, ":\") + call term_sendkeys(buf, "1234") + call VerifyScreenDump(buf, 'Test_statusline_showcmd_5', {}) + + call StopVimInTerminal(buf) endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_tabline.vim b/src/nvim/testdir/test_tabline.vim index 20a9657f32..d9bef09067 100644 --- a/src/nvim/testdir/test_tabline.vim +++ b/src/nvim/testdir/test_tabline.vim @@ -167,19 +167,41 @@ func Test_tabline_showcmd() CheckScreendump let lines =<< trim END + func MyTabLine() + return '%S' + endfunc + set showtabline=2 + set tabline=%!MyTabLine() set showcmdloc=tabline call setline(1, ['a', 'b', 'c']) + set foldopen+=jump + 1,2fold + 3 END call writefile(lines, 'XTest_tabline', 'D') let buf = RunVimInTerminal('-S XTest_tabline', {'rows': 6}) - call feedkeys("\Gl", "xt") + call term_sendkeys(buf, "g") call VerifyScreenDump(buf, 'Test_tabline_showcmd_1', {}) - call feedkeys("\1234", "xt") + " typing "gg" should open the fold + call term_sendkeys(buf, "g") call VerifyScreenDump(buf, 'Test_tabline_showcmd_2', {}) + + call term_sendkeys(buf, "\Gl") + call VerifyScreenDump(buf, 'Test_tabline_showcmd_3', {}) + + call term_sendkeys(buf, "\1234") + call VerifyScreenDump(buf, 'Test_tabline_showcmd_4', {}) + + call term_sendkeys(buf, "\:set tabline=\") + call term_sendkeys(buf, ":\") + call term_sendkeys(buf, "1234") + call VerifyScreenDump(buf, 'Test_tabline_showcmd_5', {}) + + call StopVimInTerminal(buf) endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index ab63506d3c..c25b1f1157 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -1761,6 +1761,8 @@ function Test_splitkeep_callback() call term_sendkeys(buf, ":quit\Gt") call VerifyScreenDump(buf, 'Test_splitkeep_callback_4', {}) + + call StopVimInTerminal(buf) endfunc function Test_splitkeep_fold() @@ -1791,6 +1793,8 @@ function Test_splitkeep_fold() call term_sendkeys(buf, ":wincmd k\:quit\") call VerifyScreenDump(buf, 'Test_splitkeep_fold_4', {}) + + call StopVimInTerminal(buf) endfunction function Test_splitkeep_status() @@ -1809,6 +1813,8 @@ function Test_splitkeep_status() call term_sendkeys(buf, ":call win_move_statusline(win, 1)\") call VerifyScreenDump(buf, 'Test_splitkeep_status_1', {}) + + call StopVimInTerminal(buf) endfunction function Test_new_help_window_on_error() -- cgit