summaryrefslogtreecommitdiffstats
path: root/pkg/gui/filetree
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-03-31 22:39:55 +1100
committerJesse Duffield <jessedduffield@gmail.com>2021-04-02 11:00:15 +1100
commit54910fdb76f8a699d2cfb96459b75b60485fd3f7 (patch)
treec015840a1338db2976058f080346821d7f6dfc4b /pkg/gui/filetree
parent332a3c4cbfd263c34d5f53dd971701d2ca69ab4e (diff)
refactor
Diffstat (limited to 'pkg/gui/filetree')
-rw-r--r--pkg/gui/filetree/commit_file_change_manager.go5
-rw-r--r--pkg/gui/filetree/commit_file_change_node.go15
-rw-r--r--pkg/gui/filetree/inode.go14
3 files changed, 32 insertions, 2 deletions
diff --git a/pkg/gui/filetree/commit_file_change_manager.go b/pkg/gui/filetree/commit_file_change_manager.go
index d6b70a2bd..669235ef6 100644
--- a/pkg/gui/filetree/commit_file_change_manager.go
+++ b/pkg/gui/filetree/commit_file_change_manager.go
@@ -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)
})
}
diff --git a/pkg/gui/filetree/commit_file_change_node.go b/pkg/gui/filetree/commit_file_change_node.go
index c1f99d937..011c1d954 100644
--- a/pkg/gui/filetree/commit_file_change_node.go
+++ b/pkg/gui/filetree/commit_file_change_node.go
@@ -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))
diff --git a/pkg/gui/filetree/inode.go b/pkg/gui/filetree/inode.go
index bbd1c3fb6..4357f3a8a 100644
--- a/pkg/gui/filetree/inode.go
+++ b/pkg/gui/filetree/inode.go
@@ -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)