Add a keybinding for collapsing the directory the cursor is in - #6066
Open
shunsuke44 wants to merge 2 commits into
Open
shunsuke44 wants to merge 2 commits into
shunsuke44 wants to merge 2 commits into
Conversation
Working in a deeply nested directory and wanting to fold it away means first walking the cursor up to the directory's own line and only then collapsing it. This binds that to a single key, leaving the cursor on the directory that was just collapsed so it can be repeated to fold up the tree one level at a time. The containing directory is found by scanning upwards for the first item rendered at a smaller visual depth, rather than by taking the parent of the selected item's path. Paths don't survive either of the tree's display transformations: a chain of single-child directories is compressed into one node whose path names the deepest of them, so the path's parent is often a node that doesn't exist, and with showRootItemInFileTree disabled the internal paths carry no "./" prefix. Visual depth is exactly what's on screen, so both fall out for free.
The panel renders the same tree with the same collapse/expand keys, so folding a deep directory away there meant walking the cursor up by hand in exactly the way the files panel no longer requires.
shunsuke44
force-pushed
the
collapse-parent-directory
branch
from
October 1, 2026 00:20
17ede5e to
fe54929
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've read CONTRIBUTING.md, and I know this project doesn't accept pull requests.
I'm opening this one anyway, so let me be upfront about why.
I wanted this feature badly enough to build it for my own daily use.
If it isn't to your taste, please just close it — no explanation needed, and no hard feelings. I'll keep using it in my fork either way. But I do hope that something like this makes it into lazygit one day.
PR Description
Working in a deeply nested directory and wanting to fold it away means first walking the cursor up to the directory's own line and only then collapsing it. This binds that to a single key, leaving the cursor on the directory that was just collapsed so it can be repeated to fold up the tree one level at a time.
The containing directory is found by scanning upwards for the first item rendered at a smaller visual depth, rather than by taking the parent of the selected item's path. Paths don't survive either of the tree's display transformations: a chain of single-child directories is compressed into one node whose path names the deepest of them, so the path's parent is often a node that doesn't exist, and with showRootItemInFileTree disabled the internal paths carry no "./" prefix. Visual depth is exactly what's on screen, so both fall out for free.
Please check if the PR fulfills these requirements
go generate ./...)