From 81a1d26c3eee816abaa3d0e611a8b1a0e473d3a1 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sun, 31 Jul 2022 17:06:32 +0900 Subject: vim-patch:9.0.0114: the command line takes up space even when not used Problem: The command line takes up space even when not used. Solution: Allow for 'cmdheight' to be set to zero. (Shougo Matsushita, closes vim/vim#10675, closes vim/vim#940) https://github.com/vim/vim/commit/f39cfb72629f3e7fefaf578a3faa2619cd0654f8 Omit win_redr_ruler() change: winbar may still need redraw. Omit win_update() changes: Nvim doesn't use `Rows` there. Omit redraw_asap(): removed. --- src/nvim/ex_cmds.c | 2 +- src/nvim/ex_getln.c | 3 +-- src/nvim/message.c | 2 +- src/nvim/ops.c | 21 ++++++++-------- src/nvim/screen.c | 2 +- src/nvim/testdir/test_messages.vim | 47 ++++++++++++++++++++++++++++++++++++ src/nvim/testdir/test_window_cmd.vim | 4 +-- src/nvim/window.c | 1 - 8 files changed, 62 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 7edf4c5bcb..ab6e3ac2d5 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3669,7 +3669,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T } } - bool cmdheight0 = !ui_has_messages(); + const bool cmdheight0 = !ui_has_messages(); if (cmdheight0) { // If cmdheight is 0, cmdheight must be set to 1 when we enter command line. set_option_value("ch", 1L, NULL, 0); diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 815eeb8de5..be7e7377ed 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -689,7 +689,7 @@ static void finish_incsearch_highlighting(int gotesc, incsearch_state_T *s, bool /// @param init_ccline clear ccline first static uint8_t *command_line_enter(int firstc, long count, int indent, bool init_ccline) { - bool cmdheight0 = !ui_has_messages(); + const bool cmdheight0 = !ui_has_messages(); if (cmdheight0) { // If cmdheight is 0, cmdheight must be set to 1 when we enter command line. @@ -993,7 +993,6 @@ theend: if (cmdheight0) { // Restore cmdheight set_option_value("ch", 0L, NULL, 0); - // Redraw is needed for command line completion redraw_all_later(CLEAR); } diff --git a/src/nvim/message.c b/src/nvim/message.c index 66c6cca561..621a9212df 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -1390,7 +1390,7 @@ void msg_start(void) need_fileinfo = false; } - bool no_msg_area = !ui_has_messages(); + const bool no_msg_area = !ui_has_messages(); if (need_clr_eos || (no_msg_area && redrawing_cmdline)) { // Halfway an ":echo" command and getting an (error) message: clear diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 75ba8dbede..b428bf8dd6 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -893,7 +893,7 @@ int do_record(int c) { char_u *p; static int regname; - static bool change_cmdheight = false; + static bool changed_cmdheight = false; yankreg_T *old_y_previous; int retval; @@ -907,13 +907,15 @@ int do_record(int c) showmode(); regname = c; retval = OK; + if (!ui_has_messages()) { // Enable macro indicator temporary set_option_value("ch", 1L, NULL, 0); update_screen(VALID); - change_cmdheight = true; + changed_cmdheight = true; } + apply_autocmds(EVENT_RECORDINGENTER, NULL, NULL, false, curbuf); } } else { // stop recording @@ -936,15 +938,6 @@ int do_record(int c) (void)tv_dict_add_str(dict, S_LEN("regname"), buf); tv_dict_set_keys_readonly(dict); - if (change_cmdheight) { - // Restore cmdheight - set_option_value("ch", 0L, NULL, 0); - - redraw_all_later(CLEAR); - - change_cmdheight = false; - } - // Get the recorded key hits. K_SPECIAL will be escaped, this // needs to be removed again to put it in a register. exec_reg then // adds the escaping back later. @@ -968,6 +961,12 @@ int do_record(int c) y_previous = old_y_previous; } + + if (changed_cmdheight) { + // Restore cmdheight + set_option_value("ch", 0L, NULL, 0); + redraw_all_later(CLEAR); + } } return retval; } diff --git a/src/nvim/screen.c b/src/nvim/screen.c index a28c7c63b1..5e20b35c5e 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -6501,7 +6501,7 @@ static void win_redr_ruler(win_T *wp, bool always) bool is_stl_global = global_stl_height() > 0; static bool did_show_ext_ruler = false; - // If 'ruler' off or redrawing disabled, don't do anything + // If 'ruler' off, don't do anything if (!p_ru) { return; } diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim index 2f9c562771..e6172f6c73 100644 --- a/src/nvim/testdir/test_messages.vim +++ b/src/nvim/testdir/test_messages.vim @@ -316,4 +316,51 @@ func Test_fileinfo_after_echo() call delete('b.txt') endfunc +func Test_cmdheight_zero() + set cmdheight=0 + set showcmd + redraw! + + echo 'test echo' + call assert_equal(116, screenchar(&lines, 1)) + redraw! + + echomsg 'test echomsg' + call assert_equal(116, screenchar(&lines, 1)) + redraw! + + call feedkeys(":ls\", "xt") + call assert_equal(':ls', Screenline(&lines - 1)) + redraw! + + let char = getchar(0) + call assert_match(char, 0) + + " Check change/restore cmdheight when macro + call feedkeys("qa", "xt") + call assert_equal(&cmdheight, 1) + call feedkeys("q", "xt") + call assert_equal(&cmdheight, 0) + + call setline(1, 'somestring') + call feedkeys("y", "n") + %s/somestring/otherstring/gc + call assert_equal(getline(1), 'otherstring') + + call feedkeys("g\", "xt") + call assert_match( + \ 'Col 1 of 11; Line 1 of 1; Word 1 of 1', + \ Screenline(&lines)) + + " Check split behavior + for i in range(1, 10) + split + endfor + only + call assert_equal(&cmdheight, 0) + + set cmdheight& + set showcmd& +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 3bfff0a577..d96fc2d789 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -1390,11 +1390,9 @@ func Test_win_move_statusline() call assert_equal(h0, winheight(0)) call assert_equal(1, &cmdheight) endfor - " Nvim supports cmdheight=0 + " supports cmdheight=0 set cmdheight=0 call assert_true(win_move_statusline(0, 1)) - "call assert_equal(h0, winheight(0)) - "call assert_equal(1, &cmdheight) call assert_equal(h0 + 1, winheight(0)) call assert_equal(0, &cmdheight) set cmdheight& diff --git a/src/nvim/window.c b/src/nvim/window.c index 0bd84c0269..1fe2a366a5 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -5555,7 +5555,6 @@ static void frame_setheight(frame_T *curfrp, int height) } if (curfrp->fr_parent == NULL) { - // topframe: can only change the command line 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 -- cgit From 63244f68e70f233b4175ce0018a58932f075d4c5 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sun, 31 Jul 2022 17:19:17 +0900 Subject: vim-patch:9.0.0115: when 'cmdheight' is zero pressing ':' may scroll a window Problem: When 'cmdheight' is zero pressing ':' may scroll a window. Solution: Add the made_cmdheight_nonzero flag and set 'scrolloff' to zero. https://github.com/vim/vim/commit/6747cf1671bd41cddee77c65b3f9a70509f968db --- src/nvim/ex_getln.c | 16 +++++++++++++++- src/nvim/globals.h | 3 +++ src/nvim/window.c | 3 ++- 3 files changed, 20 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index be7e7377ed..a6e8ad433f 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -692,9 +692,19 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool init const bool cmdheight0 = !ui_has_messages(); if (cmdheight0) { - // If cmdheight is 0, cmdheight must be set to 1 when we enter command line. + const long save_so = lastwin->w_p_so; + + // If cmdheight is 0, cmdheight must be set to 1 when we enter the + // command line. Set "made_cmdheight_nonzero" and reset 'scrolloff' to + // avoid scrolling the last window. + made_cmdheight_nonzero = true; + + lastwin->w_p_so = 0; set_option_value("ch", 1L, NULL, 0); update_screen(VALID); // redraw the screen NOW + + made_cmdheight_nonzero = false; + lastwin->w_p_so = save_so; } // can be invoked recursively, identify each level @@ -991,10 +1001,14 @@ theend: } if (cmdheight0) { + made_cmdheight_nonzero = true; + // Restore cmdheight set_option_value("ch", 0L, NULL, 0); // Redraw is needed for command line completion redraw_all_later(CLEAR); + + made_cmdheight_nonzero = false; } return p; diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 9946085703..4a51c08eab 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -1084,4 +1084,7 @@ EXTERN char windowsVersion[20] INIT(= { 0 }); EXTERN int exit_need_delay INIT(= 0); +// Set when 'cmdheight' is changed from non-zero to one temporarily. +EXTERN int made_cmdheight_nonzero INIT(= false); + #endif // NVIM_GLOBALS_H diff --git a/src/nvim/window.c b/src/nvim/window.c index 1fe2a366a5..7e47a4f820 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -6306,7 +6306,8 @@ void win_set_inner_size(win_T *wp) // There is no point in adjusting the scroll position when exiting. Some // values might be invalid. - if (!exiting) { + // Skip scroll_to_fraction() when 'cmdheight' was set to one from zero. + if (!exiting && !made_cmdheight_nonzero) { scroll_to_fraction(wp, prev_height); } redraw_later(wp, NOT_VALID); // SOME_VALID?? -- cgit From 2c522854c78d4e02d7337cf0b06174387f7f4583 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 31 Jul 2022 18:49:57 +0800 Subject: vim-patch:9.0.0118: no test for what patch 9.0.0155 fixes Problem: No test for what patch 9.0.0155 fixes. Solution: Add a test. Fix typos. (closes vim/vim#10822) https://github.com/vim/vim/commit/750209459c9e54030409afe8f4ad59570600b5c4 --- src/nvim/globals.h | 4 ++-- src/nvim/ops.c | 2 +- src/nvim/testdir/test_ins_complete.vim | 2 +- src/nvim/testdir/test_messages.vim | 17 +++++++++++++---- 4 files changed, 17 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 4a51c08eab..a41836353a 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -1084,7 +1084,7 @@ EXTERN char windowsVersion[20] INIT(= { 0 }); EXTERN int exit_need_delay INIT(= 0); -// Set when 'cmdheight' is changed from non-zero to one temporarily. -EXTERN int made_cmdheight_nonzero INIT(= false); +// Set when 'cmdheight' is changed from zero to one temporarily. +EXTERN bool made_cmdheight_nonzero INIT(= false); #endif // NVIM_GLOBALS_H diff --git a/src/nvim/ops.c b/src/nvim/ops.c index b428bf8dd6..0825f17ccc 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -909,7 +909,7 @@ int do_record(int c) retval = OK; if (!ui_has_messages()) { - // Enable macro indicator temporary + // Enable macro indicator temporarily set_option_value("ch", 1L, NULL, 0); update_screen(VALID); diff --git a/src/nvim/testdir/test_ins_complete.vim b/src/nvim/testdir/test_ins_complete.vim index 362c58aa31..179218e48a 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -346,7 +346,7 @@ func Test_CompleteDone_modify() \ 'user_data': '', \ } let v:completed_item = value - call assert_equal(v:completed_item, value) + call assert_equal(value, v:completed_item) endfunc func CompleteTest(findstart, query) diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim index e6172f6c73..a02d23b409 100644 --- a/src/nvim/testdir/test_messages.vim +++ b/src/nvim/testdir/test_messages.vim @@ -338,14 +338,14 @@ func Test_cmdheight_zero() " Check change/restore cmdheight when macro call feedkeys("qa", "xt") - call assert_equal(&cmdheight, 1) + call assert_equal(1, &cmdheight) call feedkeys("q", "xt") - call assert_equal(&cmdheight, 0) + call assert_equal(0, &cmdheight) call setline(1, 'somestring') call feedkeys("y", "n") %s/somestring/otherstring/gc - call assert_equal(getline(1), 'otherstring') + call assert_equal('otherstring', getline(1)) call feedkeys("g\", "xt") call assert_match( @@ -357,7 +357,16 @@ func Test_cmdheight_zero() split endfor only - call assert_equal(&cmdheight, 0) + call assert_equal(0, &cmdheight) + + " Check that pressing ":" should not scroll a window + " Check for what patch 9.0.0115 fixes + botright 10new + call setline(1, range(12)) + 7 + call feedkeys(":\"\=line('w0')\\", "xt") + call assert_equal('"1', @:) + bwipe! set cmdheight& set showcmd& -- cgit