From 0250df9b130646d55921e4571ea6350fc2a78ee3 Mon Sep 17 00:00:00 2001 From: Panagiotis Siatras Date: Sat, 5 Sep 2026 00:23:52 +0300 Subject: [PATCH 1/2] fix: hidden count raises when every row is filtered out --- lua/nvim-tree/renderer/builder.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lua/nvim-tree/renderer/builder.lua b/lua/nvim-tree/renderer/builder.lua index 41e9e1bfba8..fb151ba3c6d 100644 --- a/lua/nvim-tree/renderer/builder.lua +++ b/lua/nvim-tree/renderer/builder.lua @@ -339,7 +339,12 @@ function Builder:add_hidden_count_string(node, idx, num_children) local indent_padding = string.rep(" ", indent_width) local indent_string = indent_padding .. indent_markers.str - local line_nr = #self.lines - 1 + + -- The count hangs under the last line that was drawn. The root has no + -- such line when every one of its children is filtered out: line 0 is + -- the empty line the buffer is left with, and is where the count goes + -- instead of line -1, which nvim_buf_set_extmark rejects. + local line_nr = math.max(#self.lines - 1, 0) self.virtual_lines[line_nr] = self.virtual_lines[line_nr] or {} -- NOTE: We are inserting in depth order because of current traversal From 801fddaeb0bcd55abc80106ef30e65b2d41589a9 Mon Sep 17 00:00:00 2001 From: Panagiotis Siatras Date: Mon, 7 Sep 2026 12:17:38 +0300 Subject: [PATCH 2/2] addressed review --- lua/nvim-tree/renderer/builder.lua | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lua/nvim-tree/renderer/builder.lua b/lua/nvim-tree/renderer/builder.lua index fb151ba3c6d..c94096dfe87 100644 --- a/lua/nvim-tree/renderer/builder.lua +++ b/lua/nvim-tree/renderer/builder.lua @@ -339,11 +339,6 @@ function Builder:add_hidden_count_string(node, idx, num_children) local indent_padding = string.rep(" ", indent_width) local indent_string = indent_padding .. indent_markers.str - - -- The count hangs under the last line that was drawn. The root has no - -- such line when every one of its children is filtered out: line 0 is - -- the empty line the buffer is left with, and is where the count goes - -- instead of line -1, which nvim_buf_set_extmark rejects. local line_nr = math.max(#self.lines - 1, 0) self.virtual_lines[line_nr] = self.virtual_lines[line_nr] or {}