1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/gui/filetree/collapsed_paths.go

39 lines
839 B
Go
Raw Normal View History

2021-03-31 13:08:55 +02:00
package filetree
2022-03-19 03:26:30 +02:00
import "github.com/jesseduffield/generics/set"
2021-03-31 13:08:55 +02:00
2022-03-19 03:26:30 +02:00
type CollapsedPaths struct {
collapsedPaths *set.Set[string]
}
func NewCollapsedPaths() *CollapsedPaths {
return &CollapsedPaths{
collapsedPaths: set.New[string](),
}
}
func (self *CollapsedPaths) ExpandToPath(path string) {
2021-03-31 13:08:55 +02:00
// need every directory along the way
2021-04-08 13:24:49 +02:00
splitPath := split(path)
for i := range splitPath {
dir := join(splitPath[0 : i+1])
2022-03-19 03:26:30 +02:00
self.collapsedPaths.Remove(dir)
2021-03-31 13:08:55 +02:00
}
}
2022-03-19 03:26:30 +02:00
func (self *CollapsedPaths) IsCollapsed(path string) bool {
return self.collapsedPaths.Includes(path)
}
func (self *CollapsedPaths) Collapse(path string) {
self.collapsedPaths.Add(path)
2021-03-31 13:08:55 +02:00
}
2022-03-19 03:26:30 +02:00
func (self *CollapsedPaths) ToggleCollapsed(path string) {
if self.collapsedPaths.Includes(path) {
self.collapsedPaths.Remove(path)
} else {
self.collapsedPaths.Add(path)
}
2021-03-31 13:08:55 +02:00
}