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:
@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user