1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-01 13:17:53 +02:00
lazygit/pkg/gui/filetree/collapsed_paths.go

39 lines
839 B
Go
Raw Normal View History

2021-03-31 22:08:55 +11:00
package filetree
2022-03-19 12:26:30 +11:00
import "github.com/jesseduffield/generics/set"
2021-03-31 22:08:55 +11:00
2022-03-19 12:26:30 +11: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 22:08:55 +11:00
// need every directory along the way
2021-04-08 21:24:49 +10:00
splitPath := split(path)
for i := range splitPath {
dir := join(splitPath[0 : i+1])
2022-03-19 12:26:30 +11:00
self.collapsedPaths.Remove(dir)
2021-03-31 22:08:55 +11:00
}
}
2022-03-19 12:26:30 +11: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 22:08:55 +11:00
}
2022-03-19 12:26:30 +11:00
func (self *CollapsedPaths) ToggleCollapsed(path string) {
if self.collapsedPaths.Includes(path) {
self.collapsedPaths.Remove(path)
} else {
self.collapsedPaths.Add(path)
}
2021-03-31 22:08:55 +11:00
}