1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

make more use of generics

This commit is contained in:
Jesse Duffield
2022-03-19 12:26:30 +11:00
parent dde30fa104
commit c7a629c440
52 changed files with 3013 additions and 274 deletions

View File

@ -1,20 +1,38 @@
package filetree
type CollapsedPaths map[string]bool
import "github.com/jesseduffield/generics/set"
func (cp CollapsedPaths) ExpandToPath(path string) {
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])
cp[dir] = false
self.collapsedPaths.Remove(dir)
}
}
func (cp CollapsedPaths) IsCollapsed(path string) bool {
return cp[path]
func (self *CollapsedPaths) IsCollapsed(path string) bool {
return self.collapsedPaths.Includes(path)
}
func (cp CollapsedPaths) ToggleCollapsed(path string) {
cp[path] = !cp[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)
}
}