mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-12 11:15:00 +02:00
39 lines
839 B
Go
39 lines
839 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)
|
|
}
|
|
}
|