Merge pull request #2373 from phanithinks/clipboard_patch_option_2357

This commit is contained in:
Jesse Duffield
2023-01-31 17:02:46 +11:00
committed by GitHub
6 changed files with 100 additions and 0 deletions

View File

@@ -69,6 +69,14 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error {
}
}
menuItems = append(menuItems, []*types.MenuItem{
{
Label: "copy patch to clipboard",
OnPress: func() error { return gui.copyPatchToClipboard() },
Key: 'y',
},
}...)
return gui.c.Menu(types.CreateMenuOptions{Title: gui.c.Tr.PatchOptionsTitle, Items: menuItems})
}
@@ -192,3 +200,16 @@ func (gui *Gui) handleApplyPatch(reverse bool) error {
}
return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
}
func (gui *Gui) copyPatchToClipboard() 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.PatchCopiedToClipboard)
return nil
}