1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-06 23:46:13 +02:00

more improvements

This commit is contained in:
Jesse Duffield 2021-03-14 14:41:11 +11:00
parent 07dd9c6bc8
commit 9f2d7adb8e
4 changed files with 40 additions and 20 deletions

View File

@ -7,7 +7,8 @@ import (
type StatusLineNode struct { type StatusLineNode struct {
Children []*StatusLineNode Children []*StatusLineNode
File *File File *File
Name string Name string // e.g. 'mydir'
Path string // e.g. '/path/to/mydir'
Collapsed bool Collapsed bool
} }

View File

@ -21,14 +21,14 @@ import (
// list panel functions // list panel functions
// func (gui *Gui) getSelectedStatusNode() *models.StatusLineNode { func (gui *Gui) getSelectedStatusNode() *models.StatusLineNode {
// selectedLine := gui.State.Panels.Files.SelectedLineIdx selectedLine := gui.State.Panels.Files.SelectedLineIdx
// if selectedLine == -1 { if selectedLine == -1 {
// return nil return nil
// } }
// return gui.State.StatusLineManager.GetItemAtIndex(selectedLine) return gui.State.StatusLineManager.GetItemAtIndex(selectedLine)
// } }
func (gui *Gui) getSelectedFile() *models.File { func (gui *Gui) getSelectedFile() *models.File {
selectedLine := gui.State.Panels.Files.SelectedLineIdx selectedLine := gui.State.Panels.Files.SelectedLineIdx
@ -202,11 +202,16 @@ func (gui *Gui) enterFile(forceSecondaryFocused bool, selectedLineIdx int) error
} }
func (gui *Gui) handleFilePress() error { func (gui *Gui) handleFilePress() error {
file := gui.getSelectedFile() node := gui.getSelectedStatusNode()
if file == nil { if node == nil {
return nil return nil
} }
// need to stage or unstage depending on situation. If we have a merge conflict we can't do anything
if node.IsLeaf() {
file := node.File
if file.HasInlineMergeConflicts { if file.HasInlineMergeConflicts {
return gui.handleSwitchToMerge() return gui.handleSwitchToMerge()
} }
@ -220,6 +225,18 @@ func (gui *Gui) handleFilePress() error {
return gui.surfaceError(err) return gui.surfaceError(err)
} }
} }
} else {
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)
}
}
}
if err := gui.refreshSidePanels(refreshOptions{scope: []int{FILES}}); err != nil { if err := gui.refreshSidePanels(refreshOptions{scope: []int{FILES}}); err != nil {
return err return err

View File

@ -77,12 +77,12 @@ func (m *StatusLineManager) renderAux(s *models.StatusLineNode, prefix string, d
} }
if s.Collapsed { 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{} arr := []string{}
if !isRoot { 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 newPrefix := prefix

View File

@ -2,6 +2,7 @@ package gui
import ( import (
"os" "os"
"path/filepath"
"sort" "sort"
"strings" "strings"
@ -33,6 +34,7 @@ func GetTreeFromStatusFiles(files []*models.File) *models.StatusLineNode {
} }
newChild := &models.StatusLineNode{ newChild := &models.StatusLineNode{
Name: dir, Name: dir,
Path: filepath.Join(split[:i+1]...),
File: setFile, File: setFile,
} }
curr.Children = append(curr.Children, newChild) curr.Children = append(curr.Children, newChild)