From 5977a96b3fa8283862d5768daebdbdaae84a8b3d Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Tue, 16 Aug 2022 14:45:31 +0900 Subject: vim-patch:9.0.0190: the way 'cmdheight' can be made zero is inconsistent Problem: The way 'cmdheight' can be made zero is inconsistent. Solution: Only make 'cmdheight' zero when setting it explicitly, not when resizing windows. (closes vim/vim#10890) https://github.com/vim/vim/commit/f797e309caff48f7a56c73b16e62ff67c4dcbdd6 --- src/nvim/testdir/test_cmdline.vim | 29 +++++++++++++++++++++++++++++ src/nvim/window.c | 19 +++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index b9eefa937a..cac1491d63 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -126,6 +126,35 @@ func Test_wildmenu_screendump() call delete('XTest_wildmenu') endfunc +func Test_changing_cmdheight() + CheckScreendump + + let lines =<< trim END + set cmdheight=1 laststatus=2 + END + call writefile(lines, 'XTest_cmdheight') + + let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8}) + call term_sendkeys(buf, ":resize -3\") + call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {}) + + " using the space available doesn't change the status line + call term_sendkeys(buf, ":set cmdheight+=3\") + call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {}) + + " using more space moves the status line up + call term_sendkeys(buf, ":set cmdheight+=1\") + call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {}) + + " reducing cmdheight moves status line down + call term_sendkeys(buf, ":set cmdheight-=2\") + call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {}) + + " clean up + call StopVimInTerminal(buf) + call delete('XTest_cmdheight') +endfunc + func Test_map_completion() if !has('cmdline_compl') return diff --git a/src/nvim/window.c b/src/nvim/window.c index 9fddc59699..f567ccc556 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -5552,7 +5552,7 @@ static void frame_setheight(frame_T *curfrp, int height) } if (curfrp->fr_parent == NULL) { - // topframe: can only change the command line + // topframe: can only change the command line height if (height > ROWS_AVAIL) { // If height is greater than the available space, try to create space for // the frame by reducing 'cmdheight' if possible, while making sure @@ -5915,6 +5915,13 @@ void win_drag_status_line(win_T *dragwin, int offset) int row; bool up; // if true, drag status line up, otherwise down int n; + static bool p_ch_was_zero = false; + + // If the user explicitly set 'cmdheight' to zero, then allow for dragging + // the status line making it zero again. + if (p_ch == 0) { + p_ch_was_zero = true; + } fr = dragwin->w_frame; curfr = fr; @@ -5965,6 +5972,8 @@ void win_drag_status_line(win_T *dragwin, int offset) room = Rows - cmdline_row; if (curfr->fr_next != NULL) { room -= (int)p_ch + global_stl_height(); + } else if (!p_ch_was_zero) { + room--; } if (room < 0) { room = 0; @@ -6020,7 +6029,7 @@ void win_drag_status_line(win_T *dragwin, int offset) clear_cmdline = true; } cmdline_row = row; - p_ch = MAX(Rows - cmdline_row, 0); + p_ch = MAX(Rows - cmdline_row, p_ch_was_zero ? 0 : 1); curtab->tp_ch_used = p_ch; redraw_all_later(SOME_VALID); showmode(); @@ -6384,6 +6393,12 @@ void command_height(void) // p_ch was changed in another tab page. curtab->tp_ch_used = p_ch; + // If the space for the command line is already more than 'cmdheight' there + // is nothing to do (window size must have decreased). + if (p_ch > old_p_ch && cmdline_row <= Rows - p_ch) { + return; + } + // Find bottom frame with width of screen. frp = lastwin_nofloating()->w_frame; while (frp->fr_width != Columns && frp->fr_parent != NULL) { -- cgit From 9a6d3bd76e1edcedf71f31dfa5e1600c1c5d2c3a Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Tue, 16 Aug 2022 14:58:41 +0900 Subject: vim-patch:9.0.0191: messages test fails; window size incorrect Problem: Messages test fails; window size incorrect when 'cmdheight' is made smaller. Solution: Properly cleanup after test with cmdheight zero. Resize windows correctly when 'cmdheight' gets smaller. https://github.com/vim/vim/commit/d4cf9fc53e0b1d36e84d28ecd5595a6f102f325e N/A patches for version.c: vim-patch:9.0.0192: possible invalid memory access when 'cmdheight' is zero Problem: Possible invalid memory access when 'cmdheight' is zero. (Martin Tournoij) Solution: Avoid going over the end of w_lines[] when w_height is Rows. (closes vim/vim#10882) https://github.com/vim/vim/commit/fdc5d17d58cc9c9edc9fb2816e1afaabc531bf1e --- src/nvim/testdir/test_cmdline.vim | 5 +++++ src/nvim/testdir/test_messages.vim | 6 +++++- src/nvim/window.c | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index cac1491d63..b9f027afb2 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -150,6 +150,11 @@ func Test_changing_cmdheight() call term_sendkeys(buf, ":set cmdheight-=2\") call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {}) + " reducing window size and then setting cmdheight + call term_sendkeys(buf, ":resize -1\") + call term_sendkeys(buf, ":set cmdheight=1\") + call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {}) + " clean up call StopVimInTerminal(buf) call delete('XTest_cmdheight') diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim index e181641a3b..3a607ff533 100644 --- a/src/nvim/testdir/test_messages.vim +++ b/src/nvim/testdir/test_messages.vim @@ -376,6 +376,7 @@ func Test_fileinfo_after_echo() endfunc func Test_cmdheight_zero() + enew set cmdheight=0 set showcmd redraw! @@ -425,10 +426,13 @@ func Test_cmdheight_zero() 7 call feedkeys(":\"\=line('w0')\\", "xt") call assert_equal('"1', @:) - bwipe! + bwipe! + bwipe! set cmdheight& set showcmd& + tabnew + tabonly endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/window.c b/src/nvim/window.c index f567ccc556..b17245dd3d 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -6399,6 +6399,13 @@ void command_height(void) return; } + // If cmdline_row is smaller than what it is supposed to be for 'cmdheight' + // then set old_p_ch to what it would be, so that the windows get resized + // properly for the new value. + if (cmdline_row < Rows - p_ch) { + old_p_ch = Rows - cmdline_row; + } + // Find bottom frame with width of screen. frp = lastwin_nofloating()->w_frame; while (frp->fr_width != Columns && frp->fr_parent != NULL) { -- cgit