From 7095f8ff9d9ce3519abe34a3da4c8f4bdc3fc865 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Mon, 17 Apr 2023 17:32:32 +0100 Subject: [PATCH 1/2] vim-patch:9.0.1461: ruler not drawn correctly when using 'rulerformat' Problem: Ruler not drawn correctly when using 'rulerformat'. Solution: Adjust formatting depending on whether the ruler is drawn in the statusline or the command line. (Sean Dewar, closes vim/vim#12246) https://github.com/vim/vim/commit/fc8a601c3251c0388a88c1235b18c529385f7196 This issue was made apparent after neovim/neovim@0f1e2b6, as `showmode()` calls `win_redr_ruler()` with `curwin` now if it's floating, rather than the last window if there's no statusline (which usually already shares its right side with that of the editor). Co-authored-by: Sean Dewar --- src/nvim/statusline.c | 11 +++--- test/functional/legacy/cmdline_spec.lua | 19 +++++++++++ test/functional/ui/float_spec.lua | 45 +++++++++++++++++++++++++ test/old/testdir/test_cmdline.vim | 13 +++++++ 4 files changed, 84 insertions(+), 4 deletions(-) diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c index feb67ad6fa..5a1f7e3a7f 100644 --- a/src/nvim/statusline.c +++ b/src/nvim/statusline.c @@ -348,7 +348,8 @@ static void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler) } else { row = is_stl_global ? (Rows - (int)p_ch - 1) : W_ENDROW(wp); fillchar = fillchar_status(&attr, wp); - maxwidth = is_stl_global ? Columns : wp->w_width; + const bool in_status_line = wp->w_status_height != 0 || is_stl_global; + maxwidth = in_status_line && !is_stl_global ? wp->w_width : Columns; stl_clear_click_defs(wp->w_status_click_defs, wp->w_status_click_defs_size); wp->w_status_click_defs = stl_alloc_click_defs(wp->w_status_click_defs, maxwidth, &wp->w_status_click_defs_size); @@ -374,8 +375,8 @@ static void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler) if (col < (maxwidth + 1) / 2) { col = (maxwidth + 1) / 2; } - maxwidth = maxwidth - col; - if (!wp->w_status_height && !is_stl_global) { + maxwidth -= col; + if (!in_status_line) { grid = &msg_grid_adj; row = Rows - 1; maxwidth--; // writing in last column may cause scrolling @@ -388,7 +389,9 @@ static void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler) opt_scope = ((*wp->w_p_stl != NUL) ? OPT_LOCAL : 0); } - col += is_stl_global ? 0 : wp->w_wincol; + if (in_status_line && !is_stl_global) { + col += wp->w_wincol; + } } if (maxwidth <= 0) { diff --git a/test/functional/legacy/cmdline_spec.lua b/test/functional/legacy/cmdline_spec.lua index 2fceb6a132..f7df6ae8d7 100644 --- a/test/functional/legacy/cmdline_spec.lua +++ b/test/functional/legacy/cmdline_spec.lua @@ -239,6 +239,25 @@ describe('cmdline', function() | ]]) end) + + -- oldtest: Test_rulerformat_position() + it("ruler has correct position with 'rulerformat' set", function() + local screen = Screen.new(20, 3) + screen:set_default_attr_ids { + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + } + screen:attach() + meths.set_option('ruler', true) + meths.set_option('rulerformat', 'longish') + meths.set_option('laststatus', 0) + meths.set_option('winwidth', 1) + feed [[v|p]] + screen:expect [[ + │^ | + {0:~ }│{0:~}| + longish | + ]] + end) end) describe('cmdwin', function() diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 3203b187cc..0e1842d087 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -2295,6 +2295,51 @@ describe('float window', function() end end) + it("correct ruler position in current float with 'rulerformat' set", function() + command 'set ruler rulerformat=fish:<><' + meths.open_win(0, true, {relative='editor', width=9, height=3, row=0, col=5}) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [3:----------------------------------------]| + ## grid 2 + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + fish:<>< | + ## grid 4 + {1:^ }| + {2:~ }| + {2:~ }| + ]], float_pos={ + [4] = {{id = 1001}, "NW", 1, 0, 5, true, 50}; + }, win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}; + [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}; + }} + else + screen:expect{grid=[[ + {1:^ } | + {0:~ }{2:~ }{0: }| + {0:~ }{2:~ }{0: }| + {0:~ }| + {0:~ }| + {0:~ }| + fish:<>< | + ]]} + end + end) + it('can have minimum size', function() insert("the background text") local buf = meths.create_buf(false, true) diff --git a/test/old/testdir/test_cmdline.vim b/test/old/testdir/test_cmdline.vim index 0c6464ae80..9d506a66c0 100644 --- a/test/old/testdir/test_cmdline.vim +++ b/test/old/testdir/test_cmdline.vim @@ -3599,4 +3599,17 @@ func Test_setcmdline() cunmap a endfunc +func Test_rulerformat_position() + CheckScreendump + + let buf = RunVimInTerminal('', #{rows: 2, cols: 20}) + call term_sendkeys(buf, ":set ruler rulerformat=longish\") + call term_sendkeys(buf, ":set laststatus=0 winwidth=1\") + call term_sendkeys(buf, "\v\|\p") + call VerifyScreenDump(buf, 'Test_rulerformat_position', {}) + + " clean up + call StopVimInTerminal(buf) +endfunc + " vim: shiftwidth=2 sts=2 expandtab From 65dd3c1180cef5ec15a46bd278ab3a0cb1c3460d Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Mon, 10 Apr 2023 21:40:35 +0100 Subject: [PATCH 2/2] fix(ruler): show ruler of curwin with no statusline in cmdline Problem: After neovim/neovim@846a056, only the ruler for current floating or last window without a statusline is drawn in the cmdline. This means that if the current window is not one of these, but has no statusline, its ruler will not be drawn anymore. Solution: Make `showmode()` draw the ruler of the current window or the last window in the cmdline if it has no statusline. This also maintains the previously restored floating window case (`float->w_status_height` should be 0). This behaviour should again match Vim, but without the overdraw it seems to do to achieve the same effect; it calls `showmode()` to draw the ruler for the last window without a statusline, then may draw over it in `showruler()` (which is now `show_cursor_info_later()` in Nvim) to show the ruler for the current window..? It's very confusing. Also update the logic in `win_redr_ruler()` to mirror the check done in `showmode()`, so that the ruler doesn't potentially draw over the long ins-completion mode message in some cases. --- src/nvim/drawscreen.c | 8 +- src/nvim/statusline.c | 5 +- test/functional/ui/float_spec.lua | 115 +++++++++++++++++++++++++ test/functional/ui/statusline_spec.lua | 59 +++++++++++++ 4 files changed, 181 insertions(+), 6 deletions(-) diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c index 5ced55b2c7..810175aeba 100644 --- a/src/nvim/drawscreen.c +++ b/src/nvim/drawscreen.c @@ -1052,11 +1052,11 @@ int showmode(void) clear_showcmd(); } - // If the last window has no status line and global statusline is disabled, + // If the current or last window has no status line and global statusline is disabled, // the ruler is after the mode message and must be redrawn - win_T *last = curwin->w_floating ? curwin : lastwin_nofloating(); - if (redrawing() && last->w_status_height == 0 && global_stl_height() == 0) { - win_redr_ruler(last); + win_T *ruler_win = curwin->w_status_height == 0 ? curwin : lastwin_nofloating(); + if (redrawing() && ruler_win->w_status_height == 0 && global_stl_height() == 0) { + win_redr_ruler(ruler_win); } redraw_cmdline = false; diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c index 5a1f7e3a7f..e809922be3 100644 --- a/src/nvim/statusline.c +++ b/src/nvim/statusline.c @@ -497,7 +497,8 @@ void win_redr_ruler(win_T *wp) // Don't draw the ruler while doing insert-completion, it might overwrite // the (long) mode message. - if (wp == lastwin && lastwin->w_status_height == 0 && !is_stl_global) { + win_T *ruler_win = curwin->w_status_height == 0 ? curwin : lastwin_nofloating(); + if (wp == ruler_win && ruler_win->w_status_height == 0 && !is_stl_global) { if (edit_submode != NULL) { return; } @@ -510,7 +511,7 @@ void win_redr_ruler(win_T *wp) // Check if not in Insert mode and the line is empty (will show "0-1"). int empty_line = (State & MODE_INSERT) == 0 - && *ml_get_buf(curwin->w_buffer, curwin->w_cursor.lnum, false) == NUL; + && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, false) == NUL; int width; int row; diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 0e1842d087..e2fe0a2df5 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -2340,6 +2340,121 @@ describe('float window', function() end end) + it('does not show ruler of not-last current float during ins-completion', function() + screen:try_resize(50,9) + command 'set ruler showmode' + meths.open_win(0, false, {relative='editor', width=3, height=3, row=0, col=0}) + meths.open_win(0, false, {relative='editor', width=3, height=3, row=0, col=5}) + feed 'w' + neq('', meths.win_get_config(0).relative) + neq(funcs.winnr '$', funcs.winnr()) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [3:--------------------------------------------------]| + ## grid 2 + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + 0,0-1 All | + ## grid 4 + {1: }| + {2:~ }| + {2:~ }| + ## grid 5 + {1:^ }| + {2:~ }| + {2:~ }| + ]], float_pos={ + [5] = {{id = 1002}, "NW", 1, 0, 5, true, 50}; + [4] = {{id = 1001}, "NW", 1, 0, 0, true, 50}; + }, win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}; + [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}; + [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}; + }} + else + screen:expect{grid=[[ + {1: } {1:^ } | + {2:~ }{0: }{2:~ }{0: }| + {2:~ }{0: }{2:~ }{0: }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + 0,0-1 All | + ]]} + end + feed 'i' + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [3:--------------------------------------------------]| + ## grid 2 + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + {3:-- ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)} | + ## grid 4 + {1: }| + {2:~ }| + {2:~ }| + ## grid 5 + {1:^ }| + {2:~ }| + {2:~ }| + ]], float_pos={ + [5] = {{id = 1002}, "NW", 1, 0, 5, true, 50}; + [4] = {{id = 1001}, "NW", 1, 0, 0, true, 50}; + }, win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}; + [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}; + [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}; + }} + else + screen:expect{grid=[[ + {1: } {1:^ } | + {2:~ }{0: }{2:~ }{0: }| + {2:~ }{0: }{2:~ }{0: }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {3:-- ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)} | + ]]} + end + end) + it('can have minimum size', function() insert("the background text") local buf = meths.create_buf(false, true) diff --git a/test/functional/ui/statusline_spec.lua b/test/functional/ui/statusline_spec.lua index 8e301dc70c..c41d4983a7 100644 --- a/test/functional/ui/statusline_spec.lua +++ b/test/functional/ui/statusline_spec.lua @@ -653,3 +653,62 @@ it('ruler is redrawn in cmdline with redrawstatus #22804', function() other value | ]]) end) + +it("shows correct ruler in cmdline with no statusline", function() + clear() + local screen = Screen.new(30, 8) + screen:set_default_attr_ids { + [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [2] = {bold = true, reverse = true}, -- StatusLine + [3] = {reverse = true}, -- StatusLineNC + } + screen:attach() + -- Use long ruler to check 'ruler' with 'rulerformat' set has correct width. + command [[ + set ruler rulerformat=%{winnr()}longlonglong ls=0 winwidth=10 + split + wincmd b + vsplit + wincmd t + wincmd | + mode + ]] + -- Window 1 is current. It has a statusline, so cmdline should show the + -- last window's ruler, which has no statusline. + command '1wincmd w' + screen:expect [[ + ^ | + {1:~ }| + {1:~ }| + {2:[No Name] 1longlonglong }| + │ | + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + 3longlonglong | + ]] + -- Window 2 is current. It has no statusline, so cmdline should show its + -- ruler instead. + command '2wincmd w' + screen:expect [[ + | + {1:~ }| + {1:~ }| + {3:[No Name] 1longlonglong }| + ^ │ | + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + 2longlonglong | + ]] + -- Window 3 is current. Cmdline should again show its ruler. + command '3wincmd w' + screen:expect [[ + | + {1:~ }| + {1:~ }| + {3:[No Name] 1longlonglong }| + │^ | + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + 3longlonglong | + ]] +end)