diff --git a/lua/fff/picker_ui/file_renderer.lua b/lua/fff/picker_ui/file_renderer.lua index 20416c8c..b185dc0c 100644 --- a/lua/fff/picker_ui/file_renderer.lua +++ b/lua/fff/picker_ui/file_renderer.lua @@ -18,8 +18,9 @@ local M = {} --- Render a file item line --- @param item FileItem File item from Rust --- @param ctx ListRenderContext Render context with all state +--- @param item_idx number|nil 1-based item index in ctx.items --- @return string[] Array of line strings (always exactly 1) -function M.render_line(item, ctx) +function M.render_line(item, ctx, item_idx) -- luacheck: ignore item_idx local icons = require('fff.file_picker.icons') local lines = {} diff --git a/lua/fff/picker_ui/grep_renderer.lua b/lua/fff/picker_ui/grep_renderer.lua index 1c2595f9..ef022afc 100644 --- a/lua/fff/picker_ui/grep_renderer.lua +++ b/lua/fff/picker_ui/grep_renderer.lua @@ -254,10 +254,14 @@ end --- or 1 line [match] for subsequent matches in the same file. ---@param item FileItem Grep match item ---@param ctx table Render context +---@param item_idx number 1-based item index in ctx.items ---@return string[] -function M.render_line(item, ctx) - local is_new_group = (item.relative_path ~= ctx._grep_last_file) - ctx._grep_last_file = item.relative_path +function M.render_line(item, ctx, item_idx) + -- First rendered item in this pass always gets header — fixes missing header + -- when paginating backward in multi-page grep results (ctx is fresh per render). + local is_first_visible = (item_idx == ctx.iter_start) + local is_new_group = is_first_visible or (item.relative_path ~= ctx.grep_last_file) + ctx.grep_last_file = item.relative_path local match_line = render_match_line(item, ctx) diff --git a/lua/fff/picker_ui/list_renderer.lua b/lua/fff/picker_ui/list_renderer.lua index 57980d69..a9fccf4a 100644 --- a/lua/fff/picker_ui/list_renderer.lua +++ b/lua/fff/picker_ui/list_renderer.lua @@ -98,7 +98,7 @@ local function generate_item_lines(ctx) local item = ctx.items[i] local item_start_line = #lines + 1 - local item_lines = renderer.render_line(item, ctx) + local item_lines = renderer.render_line(item, ctx, i) vim.list_extend(lines, item_lines) local item_end_line = #lines