1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-10 22:42:00 +02:00

expand to path when switching to tree mode

This commit is contained in:
Jesse Duffield
2021-03-21 16:23:05 +11:00
parent 4b4bfae4f4
commit b5a5169372
2 changed files with 14 additions and 0 deletions

View File

@@ -848,6 +848,10 @@ func (gui *Gui) handleToggleFileTreeView() error {
gui.State.FileChangeManager.ToggleShowTree()
if path != "" {
gui.State.FileChangeManager.ExpandToPath(path)
}
// find that same node in the new format and move the cursor to it
if path != "" {
index, found := gui.State.FileChangeManager.GetIndexForPath(path)

View File

@@ -2,6 +2,7 @@ package filetree
import (
"fmt"
"os"
"strings"
"github.com/jesseduffield/lazygit/pkg/commands/models"
@@ -141,3 +142,12 @@ func (m *FileChangeManager) renderAux(s *FileChangeNode, prefix string, depth in
return arr
}
func (m *FileChangeManager) ExpandToPath(path string) {
// need every directory along the way
split := strings.Split(path, string(os.PathSeparator))
for i := range split {
dir := strings.Join(split[0:i+1], string(os.PathSeparator))
m.collapsedPaths[dir] = false
}
}