1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-04 03:48:07 +02:00

Added copy to clipboard option to the patch options

This commit is contained in:
Phanindra kumar Paladi 2023-01-17 09:07:07 +05:30
parent 6127e487dd
commit f6f82091bc
2 changed files with 23 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package gui
import (
"fmt"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@ -28,6 +29,11 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error {
OnPress: func() error { return gui.handleApplyPatch(true) },
Key: 'r',
},
{
Label: "Copy patch to clipboard",
OnPress: func() error { return gui.copyPatchToClipbaord() },
Key: gocui.KeyCtrlO,
},
}
if gui.git.Patch.PatchManager.CanRebase && gui.git.Status.WorkingTreeState() == enums.REBASE_MODE_NONE {
@ -192,3 +198,16 @@ func (gui *Gui) handleApplyPatch(reverse bool) error {
}
return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
}
func (gui *Gui) copyPatchToClipbaord() error {
patch := gui.git.Patch.PatchManager.RenderAggregatedPatchColored(true)
gui.c.LogAction(gui.c.Tr.Actions.CopyPatchToClipboard)
if err := gui.os.CopyToClipboard(patch); err != nil {
return gui.c.Error(err)
}
gui.c.Toast((gui.c.Tr.Actions.CopyPatchToClipboard))
return nil
}

View File

@ -466,6 +466,7 @@ type TranslationSet struct {
CommitURLCopiedToClipboard string
CommitMessageCopiedToClipboard string
CommitAuthorCopiedToClipboard string
PatchCopiedToClipboard string
LcCopiedToClipboard string
ErrCannotEditDirectory string
ErrStageDirWithInlineMergeConflicts string
@ -569,6 +570,7 @@ type Actions struct {
CopyCommitURLToClipboard string
CopyCommitAuthorToClipboard string
CopyCommitAttributeToClipboard string
CopyPatchToClipboard string
CustomCommand string
DiscardAllChangesInDirectory string
DiscardUnstagedChangesInDirectory string
@ -1117,6 +1119,7 @@ func EnglishTranslationSet() TranslationSet {
CommitURLCopiedToClipboard: "Commit URL copied to clipboard",
CommitMessageCopiedToClipboard: "Commit message copied to clipboard",
CommitAuthorCopiedToClipboard: "Commit author copied to clipboard",
PatchCopiedToClipboard: "Patch copied to clipboard",
LcCopiedToClipboard: "copied to clipboard",
ErrCannotEditDirectory: "Cannot edit directory: you can only edit individual files",
ErrStageDirWithInlineMergeConflicts: "Cannot stage/unstage directory containing files with inline merge conflicts. Please fix up the merge conflicts first",
@ -1201,6 +1204,7 @@ func EnglishTranslationSet() TranslationSet {
CopyCommitURLToClipboard: "Copy commit URL to clipboard",
CopyCommitAuthorToClipboard: "Copy commit author to clipboard",
CopyCommitAttributeToClipboard: "Copy to clipboard",
CopyPatchToClipboard: "Copy patch to clipboard",
MoveCommitUp: "Move commit up",
MoveCommitDown: "Move commit down",
CustomCommand: "Custom command",