Skip to content

feat(history): auto-expand commits on file navigation boundary#212

Open
fredrikaverpil wants to merge 2 commits intoesmuellert:mainfrom
fredrikaverpil:feat/history-auto-expand-commits
Open

feat(history): auto-expand commits on file navigation boundary#212
fredrikaverpil wants to merge 2 commits intoesmuellert:mainfrom
fredrikaverpil:feat/history-auto-expand-commits

Conversation

@fredrikaverpil
Copy link
Contributor

@fredrikaverpil fredrikaverpil commented Jan 29, 2026

Why?

When browsing repository history with :CodeDiff history, reaching the last file in a commit and pressing ]f wraps back to the first file of the same commit. This creates friction when reviewing changes across multiple commits.

What?

Auto-expand commits when navigating across commit boundaries:

  • Navigate next (]f): At last file → expands next commit, selects its first file
  • Navigate prev ([f): At first file → expands previous commit, selects its last file
  • Wrap-around: Last commit → first, first → last

Implementation uses shared helpers:

  • collect_commit_files: Recursively collects files (handles tree mode with nested directories)
  • find_current_position: Locates commit/file indices for boundary detection
  • update_cursor: Updates history panel cursor position

Notes

  • Uses async load_commit_files with callback pattern for responsive UI
  • Works with both list and tree view modes
  • Uses user-configured keymaps (keymaps.view.next_file/prev_file)
  • Existing navigation within expanded commits preserved

Recording

trimmed.mov

@fredrikaverpil fredrikaverpil marked this pull request as draft January 29, 2026 08:29
@fredrikaverpil fredrikaverpil force-pushed the feat/history-auto-expand-commits branch 2 times, most recently from 6738053 to 1e7f481 Compare January 29, 2026 08:39
@fredrikaverpil fredrikaverpil force-pushed the feat/history-auto-expand-commits branch from 1e7f481 to 0918d10 Compare January 29, 2026 09:07
@fredrikaverpil fredrikaverpil marked this pull request as ready for review January 29, 2026 09:08
@esmuellert
Copy link
Owner

The idea is good, and currently we indeed can't automatically expand the commit and open files in it, but I might need to take some time to look at the PR and evaluate it

When navigating files in history mode with ]f/[f, reaching the boundary
of a commit now automatically expands the adjacent commit:

- navigate_next at last file → expands next commit, selects first file
- navigate_prev at first file → expands previous commit, selects last file
- wrap-around supported (last commit → first, first → last)

Implementation uses shared helpers to reduce code duplication:
- collect_commit_files: recursively collects files (handles tree mode)
- find_current_position: locates commit/file indices for boundary detection
- update_cursor: updates history panel cursor position

Store load_commit_files on history object for access in navigation
functions, enabling async commit expansion with callback pattern.
@fredrikaverpil fredrikaverpil force-pushed the feat/history-auto-expand-commits branch from 0918d10 to e5ffe83 Compare March 1, 2026 18:52
Drop the underscore-prefixed history._load_commit_files alias and use
history.load_commit_files consistently across refresh and navigation logic.
@fredrikaverpil fredrikaverpil force-pushed the feat/history-auto-expand-commits branch from 018bf28 to b13b169 Compare March 1, 2026 19:39
@fredrikaverpil
Copy link
Contributor Author

fredrikaverpil commented Mar 1, 2026

@esmuellert I rebased on main and tidied up the implementation — unified the internal load_commit_files naming (dropping the _load_commit_files alias used by the refresh module) and resolved the merge conflicts. Also removed the POC caveat from the description; the implementation feels pretty good IMHO.

And I'm not sure what changed, but the cursor doesn't disappear off-screen anymore, as in my video recording above. It works/looks just as expected 🚀

@esmuellert
Copy link
Owner

esmuellert commented Mar 1, 2026

@esmuellert I rebased on main and tidied up the implementation — unified the internal load_commit_files naming (dropping the _load_commit_files alias used by the refresh module) and resolved the merge conflicts. Also removed the POC caveat from the description; the implementation feels pretty good IMHO.

And I'm not sure what changed, but the cursor doesn't disappear off-screen anymore, as in my video recording above. It works/looks just as expected 🚀

Thanks for your continous work! I have been working on other features, but one of my proposed enhancements is supporting more fancy history view like a git merge history graph like we see in LazyGit. It requires major data structure (like DAG or tree) change to the commits list, so I would like to hold this change a bit. I will work on this feature soon. When I decide the new design, I might merge this one then work on it, or absort it in my changes.

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.

2 participants