mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-08-24 10:13:41 -05:00
Extract a private helper function preserveSelection
The operation around which the selection should be preserved is passed in so that it can be reused for different purposes.
This commit is contained in:
@@ -167,6 +167,25 @@ func (self *FileTreeViewModel) SetStatusFilter(filter FileTreeDisplayFilter) {
|
||||
self.IListCursor.SetSelection(0)
|
||||
}
|
||||
|
||||
func (self *FileTreeViewModel) preserveSelection(f func()) {
|
||||
selectedNode := self.GetSelected()
|
||||
var selectedPath string
|
||||
if selectedNode != nil {
|
||||
selectedPath = selectedNode.GetInternalPath()
|
||||
}
|
||||
|
||||
f()
|
||||
|
||||
if selectedPath != "" {
|
||||
self.ExpandToPath(selectedPath)
|
||||
if idx, found := self.GetIndexForPath(selectedPath); found {
|
||||
self.SetSelection(idx)
|
||||
return
|
||||
}
|
||||
}
|
||||
self.ClampSelection()
|
||||
}
|
||||
|
||||
// If we're going from flat to tree we want to select the same file.
|
||||
// If we're going from tree to flat and we have a file selected we want to select that.
|
||||
// If instead we've selected a directory we need to select the first file in that directory.
|
||||
@@ -233,22 +252,9 @@ func (self *FileTreeViewModel) GetFilter() string {
|
||||
}
|
||||
|
||||
func (self *FileTreeViewModel) ClearFilter() {
|
||||
selectedNode := self.GetSelected()
|
||||
var selectedPath string
|
||||
if selectedNode != nil {
|
||||
selectedPath = selectedNode.GetInternalPath()
|
||||
}
|
||||
|
||||
self.IFileTree.SetTextFilter("", false)
|
||||
|
||||
if selectedPath != "" {
|
||||
self.ExpandToPath(selectedPath)
|
||||
if idx, found := self.GetIndexForPath(selectedPath); found {
|
||||
self.SetSelection(idx)
|
||||
return
|
||||
}
|
||||
}
|
||||
self.ClampSelection()
|
||||
self.preserveSelection(func() {
|
||||
self.IFileTree.SetTextFilter("", false)
|
||||
})
|
||||
}
|
||||
|
||||
func (self *FileTreeViewModel) ReApplyFilter(useFuzzySearch bool) {
|
||||
|
||||
Reference in New Issue
Block a user