Conversation
…file row highlight_item expanded a collapsed entry just to land the cursor on its file row. Cursor placement must not change fold state: expanding and collapsing are explicit user actions (l / h). Park the cursor on the entry row instead, consistent with the fold preservation _restore_state applies on history rebuilds. This also fixes the layout-swap path: rebuilding the panel window (e.g. jumping between M and A commits) called open() -> highlight_item, which re-expanded entries the user had collapsed.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The global API stub needs exception-safe cleanup to prevent cascading test failures.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Preserves file-history fold state when highlighting files.
Changes:
- Parks the cursor on collapsed entry rows without expanding them.
- Adds coverage for folded, expanded, and single-file behavior.
| File | Description |
|---|---|
file_history_panel.lua |
Preserves folds during highlighting. |
file_history_render_spec.lua |
Adds regression tests. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| local orig = vim.api.nvim_win_set_cursor | ||
| vim.api.nvim_win_set_cursor = function(win, pos) | ||
| calls[#calls + 1] = { win = win, pos = pos } | ||
| end | ||
| panel._restore_cursor_patch = function() |
|
I have to think more about this. It's a behavioural change, and I'm not sure that all users would find it intuitive. The current behaviour is that This affects |
|
Sorry, I need a couple more days to look into this. I didn’t mean to ignore you. I've just been a little busy. |

Problem
In the file history panel,
highlight_itemexpands a collapsed commit entry just to land the cursor on one of its file rows:This makes any navigation that calls
highlight_item(e.g.select_next_entryvia<tab>, and the layout-swap rebuild pathopen() -> highlight_itemwhen jumping between commits of different layouts, such as M -> A) silently re-expand entries the user explicitly collapsed withh.Expected
Collapsing and expanding are explicit user actions (
l/h). Cursor placement must not change fold state. This is also what_restore_statealready guarantees on history rebuilds (update_entries), so the two rebuild paths now behave consistently.Fix
Park the cursor on the entry row instead of expanding the entry:
Note on behaviour direction
The diff-view file panel's
highlight_filedeliberately expands collapsed directories to keep the active file visible. This change takes the opposite stance for the history panel: fold state is preserved on cursor placement, consistent with_restore_state. Happy to gate this behind a config option instead if that is preferred.Tests
Added three cases to
file_history_render_spec.lua:make testonfile_history_render_spec.luaandpanel_spec.luapasses;stylua --check(2.4.1 luajit) clean;make type-checkreports no new diagnostics (the 6 pre-existing deprecated warnings inpath.lua/ui/panel.luaare unrelated).