Skip to content

fix: missing filename header when scrolling up in live_grep (#470)#496

Merged
dmtrKovalenko merged 4 commits into
mainfrom
triage-bot/issue-470
Jun 14, 2026
Merged

fix: missing filename header when scrolling up in live_grep (#470)#496
dmtrKovalenko merged 4 commits into
mainfrom
triage-bot/issue-470

Conversation

@gustav-fff

Copy link
Copy Markdown
Collaborator

Closes #470

Root cause

lua/fff/grep/grep_renderer.lua:207 — file grouping logic uses ctx._grep_last_file to track consecutive matches from same file. This state resets per render (context is fresh each call). When user scrolls up past page boundary and new results load, first item in new page compared against nil → looks like different file but no way to distinguish "truly new file" from "first visible item after pagination". Result: no header rendered even though file might be same as last item on previous page.

Fix

Always render header for first visible item (ctx.iter_start). Ensures filename always shown at top of viewport regardless of pagination state. Trade-off: duplicate header if scrolling within same file, but matches user expectation — "I see a match, I need to know which file".

Steps to reproduce

Requires large repo with multi-file grep results spanning multiple pages:

```sh
cd # e.g. linux kernel, chromium, large monorepo
nvim
:lua require('fff').search('function') -- common keyword with many hits

Navigate down past first page boundary (e.g. j × 100)

Navigate back up past page boundary (e.g. k × 100)

Observe: top filename header missing on scrolled-to page

```

Expected: filename header visible for topmost match.
Actual (pre-fix): filename missing, only :line:col and content shown.

How verified

Code inspection: change targets exact root cause. Logic: is_first_visible = (item_idx == ctx.iter_start) ensures first rendered item always gets header. Checked signature match with file_renderer.render_line (third param already present but unused). Ran formatter (stylua passed).

Automated triage via gustav-fff bot.

@dmtrKovalenko dmtrKovalenko force-pushed the triage-bot/issue-470 branch from 1165af6 to 4fa96f1 Compare May 22, 2026 19:31
@dmtrKovalenko

Copy link
Copy Markdown
Owner

@gustav-fff rebase and retest thsi

First item after pagination treated as continuation of previous file
group, resulting in no header. Fix: always render header for first
visible item (iter_start) in the render pass.

Refs #470
@dmtrKovalenko dmtrKovalenko force-pushed the triage-bot/issue-470 branch from 4fa96f1 to 3a465e8 Compare June 9, 2026 20:57
@gustav-fff

Copy link
Copy Markdown
Collaborator Author

[triage-bot] DIRECTED: rebased onto main (3a465e8).

Conflict in lua/fff/picker_ui/grep_renderer.lua — main moved the file from lua/fff/grep/ and kept render_line(item, ctx) (no item_idx param). Resolved by tracking first-rendered via ctx._grep_first_rendered flag instead of comparing against ctx.iter_start. Same behavior, no signature change, list_renderer caller untouched.

CI will retest.

Honk-Honk 🪿

Comment thread lua/fff/picker_ui/grep_renderer.lua Outdated
local is_new_group = (item.relative_path ~= ctx._grep_last_file)
-- 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 = not ctx._grep_first_rendered

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this is unused?

keep this used and add this to the lua defintion params

cc @gustav-fff work on this PR and babysit it

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[triage-bot] DIRECTED: pushed fbce94b.

render_line(item, ctx, item_idx)list_renderer now passes i consistently with apply_highlights. First-visible check is item_idx == ctx.iter_start, no stateful flag. file_renderer.render_line signature updated to accept the optional param.

Honk-Honk 🪿

Replace _grep_first_rendered flag with item_idx == ctx.iter_start check.
list_renderer now passes item_idx to render_line consistently with
apply_highlights signature.
@dmtrKovalenko

Copy link
Copy Markdown
Owner

@gustav-fff _grep_last_file -> rename this to gre_last_file as it is now used

AND ACUTALLY WAIT FOR CI TO PASS BEFORE LEAVING THIS PR

Field is part of the render context API now, drop the underscore prefix.
@gustav-fff

Copy link
Copy Markdown
Collaborator Author

[triage-bot] DIRECTED: pushed 369a6a6 — renamed ctx._grep_last_file to ctx.grep_last_file (drop underscore prefix since the field is part of the render context now).

CI kicked off, currently pending across the build matrix. Will not consider this done until it goes green.

Honk-Honk 🪿

@dmtrKovalenko

Copy link
Copy Markdown
Owner

@gustav-fff fix the luacheck lint

@gustav-fff

Copy link
Copy Markdown
Collaborator Author

[triage-bot] DIRECTED: pushed ab5301c.

lua/fff/picker_ui/file_renderer.lua:23 — added -- luacheck: ignore item_idx on the signature. The param is intentionally unused in file_renderer (only grep_renderer consumes it), keeping the shared render_line(item, ctx, item_idx) shape that list_renderer calls through.

Honk-Honk 🪿

@dmtrKovalenko dmtrKovalenko merged commit 733431e into main Jun 14, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Top file name is missing

2 participants