summaryrefslogtreecommitdiffstats
path: root/pkg/gui/filetree/collapsed_paths.go
blob: 903999b37d04c8013664975caa8bf27a9dd610bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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)
	}
}