diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-03-14 14:41:11 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-03-30 21:57:00 +1100 |
commit | 9f2d7adb8ea8135b402cda8cbb84a97744ec7357 (patch) | |
tree | 974c3118b1dcc810dcbc54ed12b63d744b9959fb /pkg | |
parent | 07dd9c6bc8e16632a055c0d705800dc1198fb8f0 (diff) |
more improvements
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/commands/models/status_line_node.go | 3 | ||||
-rw-r--r-- | pkg/gui/files_panel.go | 51 | ||||
-rw-r--r-- | pkg/gui/status_line_manager.go | 4 | ||||
-rw-r--r-- | pkg/gui/status_tree.go | 2 |
4 files changed, 40 insertions, 20 deletions
diff --git a/pkg/commands/models/status_line_node.go b/pkg/commands/models/status_line_node.go index 042a0fceb..f2031888b 100644 --- a/pkg/commands/models/status_line_node.go +++ b/pkg/commands/models/status_line_node.go @@ -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 } diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 8a388f9a0..06a57af60 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -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) + } } } diff --git a/pkg/gui/status_line_manager.go b/pkg/gui/status_line_manager.go index 9510e744f..f786c1bc4 100644 --- a/pkg/gui/status_line_manager.go +++ b/pkg/gui/status_line_manager.go @@ -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 diff --git a/pkg/gui/status_tree.go b/pkg/gui/status_tree.go index 758f308a7..77a02ce51 100644 --- a/pkg/gui/status_tree.go +++ b/pkg/gui/status_tree.go @@ -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) |