diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 360c10be6..441f69b3f 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -460,15 +460,6 @@ func (gui *Gui) currentBranch() *commands.Branch { return gui.State.Branches[0] } -func (gui *Gui) handleClipboardCopyBranch(g *gocui.Gui, v *gocui.View) error { - branch := gui.getSelectedBranch() - if branch == nil { - return nil - } - - return gui.OSCommand.CopyToClipboard(branch.Name) -} - func (gui *Gui) handleNewBranchOffCurrentItem() error { context := gui.currentSideContext() diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index e1bd262bf..9737d5681 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -571,12 +571,3 @@ func (gui *Gui) handleGotoBottomForCommitsPanel(g *gocui.Gui, v *gocui.View) err return nil } - -func (gui *Gui) handleClipboardCopyCommit(g *gocui.Gui, v *gocui.View) error { - commit := gui.getSelectedLocalCommit() - if commit == nil { - return nil - } - - return gui.OSCommand.CopyToClipboard(commit.Sha) -} diff --git a/pkg/gui/context.go b/pkg/gui/context.go index e5018b26b..e3a90871b 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -693,3 +693,12 @@ func (gui *Gui) getCurrentSideView() *gocui.View { return view } + +func (gui *Gui) getSideContextSelectedItem() ListItem { + currentSideContext := gui.currentSideContext() + if currentSideContext == nil { + return nil + } + + return currentSideContext.GetSelectedItem() +} diff --git a/pkg/gui/global_handlers.go b/pkg/gui/global_handlers.go index b1cedd63b..c2ae9cae8 100644 --- a/pkg/gui/global_handlers.go +++ b/pkg/gui/global_handlers.go @@ -178,3 +178,14 @@ func (gui *Gui) fetch(canPromptForCredentials bool) (err error) { return err } + +func (gui *Gui) handleCopySelectedSideContextItemToClipboard() error { + // important to note that this assumes we've selected an item in a side context + item := gui.getSideContextSelectedItem() + + if item == nil { + return nil + } + + return gui.OSCommand.CopyToClipboard(item.ID()) +} diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 9e377690c..4eee9f5c5 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -552,7 +552,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { ViewName: "branches", Contexts: []string{LOCAL_BRANCHES_CONTEXT_KEY}, Key: gui.getKey("universal.copyToClipboard"), - Handler: gui.handleClipboardCopyBranch, + Handler: gui.wrappedHandler(gui.handleCopySelectedSideContextItemToClipboard), Description: gui.Tr.SLocalize("copyBranchNameToClipboard"), }, { @@ -765,7 +765,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { ViewName: "commits", Contexts: []string{BRANCH_COMMITS_CONTEXT_KEY}, Key: gui.getKey("universal.copyToClipboard"), - Handler: gui.handleClipboardCopyCommit, + Handler: gui.wrappedHandler(gui.handleCopySelectedSideContextItemToClipboard), Description: gui.Tr.SLocalize("copyCommitShaToClipboard"), }, { @@ -860,6 +860,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { Handler: gui.wrappedHandler(gui.exitCherryPickingMode), Description: gui.Tr.SLocalize("resetCherryPick"), }, + { + ViewName: "commits", + Contexts: []string{REFLOG_COMMITS_CONTEXT_KEY}, + Key: gui.getKey("universal.copyToClipboard"), + Handler: gui.wrappedHandler(gui.handleCopySelectedSideContextItemToClipboard), + Description: gui.Tr.SLocalize("copyCommitShaToClipboard"), + }, { ViewName: "branches", Contexts: []string{SUB_COMMITS_CONTEXT_KEY}, @@ -909,6 +916,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { Handler: gui.wrappedHandler(gui.exitCherryPickingMode), Description: gui.Tr.SLocalize("resetCherryPick"), }, + { + ViewName: "branches", + Contexts: []string{SUB_COMMITS_CONTEXT_KEY}, + Key: gui.getKey("universal.copyToClipboard"), + Handler: gui.wrappedHandler(gui.handleCopySelectedSideContextItemToClipboard), + Description: gui.Tr.SLocalize("copyCommitShaToClipboard"), + }, { ViewName: "stash", Key: gui.getKey("universal.goInto"),