This commit is contained in:
Jesse Duffield
2021-03-31 22:39:55 +11:00
parent 332a3c4cbf
commit 54910fdb76
9 changed files with 76 additions and 35 deletions

View File

@@ -2,6 +2,7 @@ package filetree
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/patch"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/sirupsen/logrus"
)
@@ -87,9 +88,9 @@ func (m *CommitFileChangeManager) ToggleCollapsed(path string) {
m.collapsedPaths.ToggleCollapsed(path)
}
func (m *CommitFileChangeManager) Render(diffName string) []string {
func (m *CommitFileChangeManager) Render(diffName string, patchManager *patch.PatchManager) []string {
return renderAux(m.tree, m.collapsedPaths, "", -1, func(n INode, depth int) string {
castN := n.(*CommitFileChangeNode)
return presentation.GetCommitFileLine(castN.NameAtDepth(depth), diffName, castN.File)
return presentation.GetCommitFileLine(castN.NameAtDepth(depth), diffName, castN.File, patchManager)
})
}

View File

@@ -81,6 +81,21 @@ func (s *CommitFileChangeNode) Any(test func(node *CommitFileChangeNode) bool) b
})
}
func (s *CommitFileChangeNode) Every(test func(node *CommitFileChangeNode) bool) bool {
return every(s, func(n INode) bool {
castNode := n.(*CommitFileChangeNode)
return test(castNode)
})
}
func (s *CommitFileChangeNode) EveryFile(test func(file *models.CommitFile) bool) bool {
return every(s, func(n INode) bool {
castNode := n.(*CommitFileChangeNode)
return castNode.File == nil || test(castNode.File)
})
}
func (n *CommitFileChangeNode) Flatten(collapsedPaths map[string]bool) []*CommitFileChangeNode {
results := flatten(n, collapsedPaths)
nodes := make([]*CommitFileChangeNode, len(results))

View File

@@ -77,6 +77,20 @@ func any(node INode, test func(INode) bool) bool {
return false
}
func every(node INode, test func(INode) bool) bool {
if !test(node) {
return false
}
for _, child := range node.GetChildren() {
if !every(child, test) {
return false
}
}
return true
}
func flatten(node INode, collapsedPaths map[string]bool) []INode {
result := []INode{}
result = append(result, node)