From 81261804a8e335f9a97f0c4b2e8e70c59593ccca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Hoffmann?= Date: Sat, 1 Aug 2026 12:29:54 +0200 Subject: [PATCH] fix(ruler): always clear ruler when disabled Problem: the ruler is not cleared in the following circumstances: - ui1 is running - 'rulerformat' is configured - the default ruler was not previously visible in the last line, for example because 'rulerformat' is configured in init.lua - 'ruler' is disabled without using the command-line, for example via key-binding (entering the command-line would clear the ruler) The corresponding test case did not fail because 'rulerformat' was set while the default ruler was shown. Solution: use a dedicated variable for tracking whether the ui1 ruler was previously shown in the last line. `did_ruler_col` is now only used for setting `msg_col`, which is not implemented in the case where 'rulerformat' is configured. Reorder the test code to make the individual checks more independent from each other, and to reflect the future where 'rulerformat' will never be empty. Note that the check where 'rulerformat' was configured relied on the default ruler not being cleared and a stale "0," still being shown in front of the new ruler - this is also fixed with ui2. --- src/nvim/statusline.c | 6 ++++++ test/functional/ui/messages_spec.lua | 32 ++++++++++++++-------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c index 51bafb4238..01726a0a8f 100644 --- a/src/nvim/statusline.c +++ b/src/nvim/statusline.c @@ -482,6 +482,7 @@ void win_redr_winbar(win_T *wp) void redraw_ruler(void) { + static bool did_show_ruler = false; static int did_ruler_col = -1; win_T *wp = !curwin->w_config.hide && curwin->w_status_height == 0 ? curwin : lastwin_nofloating(NULL); @@ -495,8 +496,11 @@ void redraw_ruler(void) } else if (did_ruler_col > 0) { msg_col = did_ruler_col; msg_row = Rows - 1; + } + if (did_show_ruler && !ui_has(kUIMessages)) { msg_clr_eos(); } + did_show_ruler = false; did_ruler_col = -1; return; } @@ -516,6 +520,7 @@ void redraw_ruler(void) bool part_of_status = wp->w_status_height || is_stl_global; if (*p_ruf && (p_ch > 0 || (ui_has(kUIMessages) && !part_of_status))) { win_redr_stl_expr(wp, false, true, ui_has(kUIMessages)); + did_show_ruler = !ui_has(kUIMessages); return; } @@ -605,6 +610,7 @@ void redraw_ruler(void) } grid_line_start(&msg_grid_adj, Rows - 1); + did_show_ruler = true; did_ruler_col = off + this_ru_col; int w = grid_line_puts(did_ruler_col, buffer, -1, attr); grid_line_fill(did_ruler_col + w, off + width, fillchar, attr); diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua index e63068fe56..29119bda3f 100644 --- a/test/functional/ui/messages_spec.lua +++ b/test/functional/ui/messages_spec.lua @@ -1890,7 +1890,22 @@ describe('ui/builtin messages', function() end) it('supports ruler with laststatus=0', function() - command('set ruler laststatus=0') + command('set laststatus=0 ruler rulerformat=%-15(%c%V\\ %p%%%)') + screen:expect([[ + ^ | + {1:~ }|*5 + 0-1 100% | + ]]) + + -- Ruler is cleared when it is no longer drawn. + command('set noruler') + screen:expect([[ + ^ | + {1:~ }|*5 + | + ]]) + + command('set ruler rulerformat&') screen:expect([[ ^ | {1:~ }|*5 @@ -1903,21 +1918,6 @@ describe('ui/builtin messages', function() {1:~ }|*5 {101: 0,0-1 All }| ]]) - - command('set rulerformat=%15(%c%V\\ %p%%%)') - screen:expect([[ - ^ | - {1:~ }|*5 - {101: 0,0-1 100% }| - ]]) - - -- Ruler is cleared when it is no longer drawn. - command('set noruler') - screen:expect([[ - ^ | - {1:~ }|*5 - {101: }| - ]]) end) it('supports echo with CRLF line separators', function()