summaryrefslogtreecommitdiffstats
path: root/pkg/gui/commits_panel.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-08-22 09:55:49 +1000
committerJesse Duffield <jessedduffield@gmail.com>2020-08-23 14:29:18 +1000
commitf63ec38aae9800a05d1b39977c8b51f6f1d4201c (patch)
treeedf9faf72b0b14df16a8cc4a73c7ce12d0f2ef62 /pkg/gui/commits_panel.go
parentf858c8e7509526b2e174e9aa83c54a4aea146b38 (diff)
genericise creating new branches off things
Diffstat (limited to 'pkg/gui/commits_panel.go')
-rw-r--r--pkg/gui/commits_panel.go28
1 files changed, 19 insertions, 9 deletions
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go
index db3aea4df..5e1c55c58 100644
--- a/pkg/gui/commits_panel.go
+++ b/pkg/gui/commits_panel.go
@@ -675,25 +675,35 @@ func (gui *Gui) handleClipboardCopyCommit(g *gocui.Gui, v *gocui.View) error {
return gui.OSCommand.CopyToClipboard(commit.Sha)
}
-func (gui *Gui) handleNewBranchOffCommit() error {
- commit := gui.getSelectedLocalCommit()
- if commit == nil {
- return nil
- }
+func (gui *Gui) handleNewBranchOffCurrentItem() error {
+ context := gui.currentSideContext()
+
+ itemId := context.GetSelectedItemId()
message := gui.Tr.TemplateLocalize(
"NewBranchNameBranchOff",
Teml{
- "branchName": commit.NameWithSha(),
+ "branchName": itemId, // TODO: add 'long name' field on ListItem interface (right now we just get an ugly commit SHA for commits)
},
)
return gui.prompt(gui.getCurrentSideView(), message, "", func(response string) error {
- if err := gui.GitCommand.NewBranch(response, commit.Sha); err != nil {
+ if err := gui.GitCommand.NewBranch(response, itemId); err != nil {
return err
}
- gui.State.Panels.Commits.SelectedLineIdx = 0
- gui.State.Panels.Branches.SelectedLineIdx = 0
+
+ // if we're currently in the branch commits context then the selected commit
+ // is about to go to the top of the list
+ if context.GetKey() == BRANCH_COMMITS_CONTEXT_KEY {
+ context.GetPanelState().SetSelectedLineIdx(0)
+ }
+
+ if context.GetKey() != gui.Contexts.Branches.Context.GetKey() {
+ if err := gui.switchContext(gui.Contexts.Branches.Context); err != nil {
+ return err
+ }
+ gui.State.Panels.Branches.SelectedLineIdx = 0
+ }
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
})