mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-27 23:08:02 +02:00
more improvements
This commit is contained in:
parent
07dd9c6bc8
commit
9f2d7adb8e
@ -7,7 +7,8 @@ import (
|
||||
type StatusLineNode struct {
|
||||
Children []*StatusLineNode
|
||||
File *File
|
||||
Name string
|
||||
Name string // e.g. 'mydir'
|
||||
Path string // e.g. '/path/to/mydir'
|
||||
Collapsed bool
|
||||
}
|
||||
|
||||
|
@ -21,14 +21,14 @@ import (
|
||||
|
||||
// list panel functions
|
||||
|
||||
// func (gui *Gui) getSelectedStatusNode() *models.StatusLineNode {
|
||||
// selectedLine := gui.State.Panels.Files.SelectedLineIdx
|
||||
// if selectedLine == -1 {
|
||||
// return nil
|
||||
// }
|
||||
func (gui *Gui) getSelectedStatusNode() *models.StatusLineNode {
|
||||
selectedLine := gui.State.Panels.Files.SelectedLineIdx
|
||||
if selectedLine == -1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// return gui.State.StatusLineManager.GetItemAtIndex(selectedLine)
|
||||
// }
|
||||
return gui.State.StatusLineManager.GetItemAtIndex(selectedLine)
|
||||
}
|
||||
|
||||
func (gui *Gui) getSelectedFile() *models.File {
|
||||
selectedLine := gui.State.Panels.Files.SelectedLineIdx
|
||||
@ -202,22 +202,39 @@ func (gui *Gui) enterFile(forceSecondaryFocused bool, selectedLineIdx int) error
|
||||
}
|
||||
|
||||
func (gui *Gui) handleFilePress() error {
|
||||
file := gui.getSelectedFile()
|
||||
if file == nil {
|
||||
node := gui.getSelectedStatusNode()
|
||||
if node == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if file.HasInlineMergeConflicts {
|
||||
return gui.handleSwitchToMerge()
|
||||
}
|
||||
// need to stage or unstage depending on situation. If we have a merge conflict we can't do anything
|
||||
|
||||
if file.HasUnstagedChanges {
|
||||
if err := gui.GitCommand.StageFile(file.Name); err != nil {
|
||||
return gui.surfaceError(err)
|
||||
if node.IsLeaf() {
|
||||
file := node.File
|
||||
|
||||
if file.HasInlineMergeConflicts {
|
||||
return gui.handleSwitchToMerge()
|
||||
}
|
||||
|
||||
if file.HasUnstagedChanges {
|
||||
if err := gui.GitCommand.StageFile(file.Name); err != nil {
|
||||
return gui.surfaceError(err)
|
||||
}
|
||||
} else {
|
||||
if err := gui.GitCommand.UnStageFile(file.Name, file.Tracked); err != nil {
|
||||
return gui.surfaceError(err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if err := gui.GitCommand.UnStageFile(file.Name, file.Tracked); err != nil {
|
||||
return gui.surfaceError(err)
|
||||
if node.HasUnstagedChanges() {
|
||||
if err := gui.GitCommand.StageFile(node.Path); err != nil {
|
||||
return gui.surfaceError(err)
|
||||
}
|
||||
} else {
|
||||
// pretty sure it doesn't matter that we're always passing true here
|
||||
if err := gui.GitCommand.UnStageFile(node.Path, true); err != nil {
|
||||
return gui.surfaceError(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,12 +77,12 @@ func (m *StatusLineManager) renderAux(s *models.StatusLineNode, prefix string, d
|
||||
}
|
||||
|
||||
if s.Collapsed {
|
||||
return []string{fmt.Sprintf("%s%s %s", prefix, s.Name, COLLAPSED_ARROW)}
|
||||
return []string{fmt.Sprintf("%s %s", getLine(), COLLAPSED_ARROW)}
|
||||
}
|
||||
|
||||
arr := []string{}
|
||||
if !isRoot {
|
||||
arr = append(arr, fmt.Sprintf("%s%s %s", prefix, s.Name, EXPANDED_ARROW))
|
||||
arr = append(arr, fmt.Sprintf("%s %s", getLine(), EXPANDED_ARROW))
|
||||
}
|
||||
|
||||
newPrefix := prefix
|
||||
|
@ -2,6 +2,7 @@ package gui
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@ -33,6 +34,7 @@ func GetTreeFromStatusFiles(files []*models.File) *models.StatusLineNode {
|
||||
}
|
||||
newChild := &models.StatusLineNode{
|
||||
Name: dir,
|
||||
Path: filepath.Join(split[:i+1]...),
|
||||
File: setFile,
|
||||
}
|
||||
curr.Children = append(curr.Children, newChild)
|
||||
|
Loading…
x
Reference in New Issue
Block a user