From f6f82091bceb48f7f08580e58f814d9328c82e5d Mon Sep 17 00:00:00 2001 From: Phanindra kumar Paladi Date: Tue, 17 Jan 2023 09:07:07 +0530 Subject: [PATCH] Added copy to clipboard option to the patch options --- pkg/gui/custom_patch_options_panel.go | 19 +++++++++++++++++++ pkg/i18n/english.go | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/pkg/gui/custom_patch_options_panel.go b/pkg/gui/custom_patch_options_panel.go index a508c7b44..e41849cb1 100644 --- a/pkg/gui/custom_patch_options_panel.go +++ b/pkg/gui/custom_patch_options_panel.go @@ -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 +} diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index f1c081018..21451a8b9 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -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",