1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-21 12:16:54 +02:00
lazygit/pkg/gui/filetree/collapsed_paths.go
Mauricio Trajano 7bea41534b Collapse/expand all files in tree
Co-authored-by: Stefan Haller <stefan@haller-berlin.de>
2025-01-13 21:13:11 +01:00

44 lines
1000 B
Go

package filetree
import "github.com/jesseduffield/generics/set"
type CollapsedPaths struct {
collapsedPaths *set.Set[string]
}
func NewCollapsedPaths() *CollapsedPaths {
return &CollapsedPaths{
collapsedPaths: set.New[string](),
}
}
func (self *CollapsedPaths) ExpandToPath(path string) {
// need every directory along the way
splitPath := split(path)
for i := range splitPath {
dir := join(splitPath[0 : i+1])
self.collapsedPaths.Remove(dir)
}
}
func (self *CollapsedPaths) IsCollapsed(path string) bool {
return self.collapsedPaths.Includes(path)
}
func (self *CollapsedPaths) Collapse(path string) {
self.collapsedPaths.Add(path)
}
func (self *CollapsedPaths) ToggleCollapsed(path string) {
if self.collapsedPaths.Includes(path) {
self.collapsedPaths.Remove(path)
} else {
self.collapsedPaths.Add(path)
}
}
func (self *CollapsedPaths) ExpandAll() {
// Could be cleaner if Set had a Clear() method...
self.collapsedPaths.RemoveSlice(self.collapsedPaths.ToSlice())
}