MCPcopy
hub / github.com/jesseduffield/lazygit / SetTree

Method SetTree

pkg/gui/filetree/file_tree_view_model.go:103–128  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

101}
102
103func (self *FileTreeViewModel) SetTree() {
104 newFiles := self.GetAllFiles()
105 selectedNode := self.GetSelected()
106
107 // for when you stage the old file of a rename and the new file is in a collapsed dir
108 for _, file := range newFiles {
109 if selectedNode != nil && selectedNode.path != "" && file.PreviousPath == selectedNode.path {
110 self.ExpandToPath(file.Path)
111 }
112 }
113
114 prevNodes := self.GetAllItems()
115 prevSelectedLineIdx := self.GetSelectedLineIdx()
116
117 self.IFileTree.SetTree()
118
119 if selectedNode != nil {
120 newNodes := self.GetAllItems()
121 newIdx := self.findNewSelectedIdx(prevNodes[prevSelectedLineIdx:], newNodes)
122 if newIdx != -1 && newIdx != prevSelectedLineIdx {
123 self.SetSelection(newIdx)
124 }
125 }
126
127 self.ClampSelection()
128}
129
130// Let's try to find our file again and move the cursor to that.
131// If we can't find our file, it was probably just removed by the user. In that

Callers

nothing calls this directly

Calls 9

GetSelectedMethod · 0.95
findNewSelectedIdxMethod · 0.95
GetAllFilesMethod · 0.65
ExpandToPathMethod · 0.65
GetAllItemsMethod · 0.65
GetSelectedLineIdxMethod · 0.65
SetTreeMethod · 0.65
SetSelectionMethod · 0.65
ClampSelectionMethod · 0.65

Tested by

no test coverage detected