WIP Try to fix some problems, e.g. switch between tree and flat view
This commit is contained in:
@@ -477,7 +477,7 @@ func (self *CommitFilesController) enterCommitFile(node *filetree.CommitFileNode
|
||||
}
|
||||
|
||||
func (self *CommitFilesController) handleToggleCommitFileDirCollapsed(node *filetree.CommitFileNode) error {
|
||||
self.context().CommitFileTreeViewModel.ToggleCollapsed(node.GetPath())
|
||||
self.context().CommitFileTreeViewModel.ToggleCollapsed(node.GetInternalPath())
|
||||
|
||||
self.c.PostRefreshUpdate(self.context())
|
||||
|
||||
|
||||
@@ -1072,7 +1072,7 @@ func (self *FilesController) handleToggleDirCollapsed() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
self.context().FileTreeViewModel.ToggleCollapsed(node.GetPath())
|
||||
self.context().FileTreeViewModel.ToggleCollapsed(node.GetInternalPath())
|
||||
|
||||
self.c.PostRefreshUpdate(self.c.Contexts().Files)
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ type Node[T any] struct {
|
||||
Children []*Node[T]
|
||||
|
||||
// path of the file/directory
|
||||
// private; use GetPath() to access
|
||||
// private; use either GetPath() or GetInternalPath() to access
|
||||
path string
|
||||
|
||||
// rather than render a tree as:
|
||||
@@ -47,11 +47,20 @@ func (self *Node[T]) GetFile() *T {
|
||||
return self.File
|
||||
}
|
||||
|
||||
// This returns the logical path from the user's point of view. It is the
|
||||
// relative path from the root of the repository.
|
||||
// Use this for display, or when you want to perform some action on the path
|
||||
// (e.g. a git command).
|
||||
func (self *Node[T]) GetPath() string {
|
||||
return strings.TrimPrefix(self.path, "./")
|
||||
}
|
||||
|
||||
func (self *Node[T]) GetFullPath() string {
|
||||
// This returns the internal path from the tree's point of view. It's the same
|
||||
// as GetPath() except that it has a "./" prefix when we are showing a root
|
||||
// item.
|
||||
// Use this when interacting with the tree itself, e.g. when calling
|
||||
// ToggleCollapsed.
|
||||
func (self *Node[T]) GetInternalPath() string {
|
||||
return self.path
|
||||
}
|
||||
|
||||
@@ -94,7 +103,7 @@ func (self *Node[T]) SortChildren() {
|
||||
return false
|
||||
}
|
||||
|
||||
return a.GetPath() < b.GetPath()
|
||||
return a.path < b.path
|
||||
})
|
||||
|
||||
// TODO: think about making this in-place
|
||||
@@ -164,7 +173,7 @@ func (self *Node[T]) EveryFile(test func(*T) bool) bool {
|
||||
func (self *Node[T]) Flatten(collapsedPaths *CollapsedPaths) []*Node[T] {
|
||||
result := []*Node[T]{self}
|
||||
|
||||
if len(self.Children) > 0 && !collapsedPaths.IsCollapsed(self.GetPath()) {
|
||||
if len(self.Children) > 0 && !collapsedPaths.IsCollapsed(self.path) {
|
||||
result = append(result, lo.FlatMap(self.Children, func(child *Node[T], _ int) []*Node[T] {
|
||||
return child.Flatten(collapsedPaths)
|
||||
})...)
|
||||
@@ -190,7 +199,7 @@ func (self *Node[T]) getNodeAtIndexAux(index int, collapsedPaths *CollapsedPaths
|
||||
return self, offset
|
||||
}
|
||||
|
||||
if !collapsedPaths.IsCollapsed(self.GetPath()) {
|
||||
if !collapsedPaths.IsCollapsed(self.path) {
|
||||
for _, child := range self.Children {
|
||||
foundNode, offsetChange := child.getNodeAtIndexAux(index-offset, collapsedPaths)
|
||||
offset += offsetChange
|
||||
@@ -206,11 +215,11 @@ func (self *Node[T]) getNodeAtIndexAux(index int, collapsedPaths *CollapsedPaths
|
||||
func (self *Node[T]) GetIndexForPath(path string, collapsedPaths *CollapsedPaths) (int, bool) {
|
||||
offset := 0
|
||||
|
||||
if self.GetPath() == path {
|
||||
if self.path == path {
|
||||
return offset, true
|
||||
}
|
||||
|
||||
if !collapsedPaths.IsCollapsed(self.GetPath()) {
|
||||
if !collapsedPaths.IsCollapsed(self.path) {
|
||||
for _, child := range self.Children {
|
||||
offsetChange, found := child.GetIndexForPath(path, collapsedPaths)
|
||||
offset += offsetChange + 1
|
||||
@@ -230,7 +239,7 @@ func (self *Node[T]) Size(collapsedPaths *CollapsedPaths) int {
|
||||
|
||||
output := 1
|
||||
|
||||
if !collapsedPaths.IsCollapsed(self.GetPath()) {
|
||||
if !collapsedPaths.IsCollapsed(self.path) {
|
||||
for _, child := range self.Children {
|
||||
output += child.Size(collapsedPaths)
|
||||
}
|
||||
|
||||
@@ -91,11 +91,11 @@ func renderAux[T any](
|
||||
|
||||
arr := []string{}
|
||||
if !isRoot {
|
||||
isCollapsed := collapsedPaths.IsCollapsed(node.GetPath())
|
||||
isCollapsed := collapsedPaths.IsCollapsed(node.GetInternalPath())
|
||||
arr = append(arr, renderLine(node, treeDepth, visualDepth, isCollapsed))
|
||||
}
|
||||
|
||||
if collapsedPaths.IsCollapsed(node.GetPath()) {
|
||||
if collapsedPaths.IsCollapsed(node.GetInternalPath()) {
|
||||
return arr
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ func getColorForChangeStatus(changeStatus string) style.TextStyle {
|
||||
}
|
||||
|
||||
func fileNameAtDepth(node *filetree.Node[models.File], depth int) string {
|
||||
splitName := split(node.GetFullPath())
|
||||
splitName := split(node.GetInternalPath())
|
||||
if depth == 0 && splitName[0] == "." {
|
||||
if len(splitName) == 1 {
|
||||
return "<root>"
|
||||
@@ -320,7 +320,7 @@ func fileNameAtDepth(node *filetree.Node[models.File], depth int) string {
|
||||
}
|
||||
|
||||
func commitFileNameAtDepth(node *filetree.Node[models.CommitFile], depth int) string {
|
||||
splitName := split(node.GetFullPath())
|
||||
splitName := split(node.GetInternalPath())
|
||||
if depth == 0 && splitName[0] == "." {
|
||||
if len(splitName) == 1 {
|
||||
return "<root>"
|
||||
|
||||
Reference in New Issue
Block a user