1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-11-25 22:32:13 +02:00

Add "CopyToClipboard" command to ConfirmationController

This commit is contained in:
kyu08
2025-08-10 19:04:00 +09:00
committed by Stefan Haller
parent 0573529f8a
commit 3fa5a8eddd
5 changed files with 75 additions and 0 deletions

View File

@@ -47,6 +47,13 @@ func (self *ConfirmationController) GetKeybindings(opts types.KeybindingsOpts) [
return nil
},
},
{
Key: opts.GetKey(opts.Config.Universal.CopyToClipboard),
Handler: self.handleCopyToClipboard,
Description: self.c.Tr.CopyToClipboardMenu,
DisplayOnScreen: true,
GetDisabledReason: self.copyToClipboardEnabled,
},
}
return bindings
@@ -93,3 +100,23 @@ func (self *ConfirmationController) switchToSuggestions() {
self.c.Views().Suggestions.Subtitle = subtitle
self.c.Context().Replace(self.c.Contexts().Suggestions)
}
func (self *ConfirmationController) handleCopyToClipboard() error {
confirmationView := self.c.Views().Confirmation
text := confirmationView.Buffer()
if err := self.c.OS().CopyToClipboard(text); err != nil {
return err
}
self.c.Toast(self.c.Tr.MessageCopiedToClipboard)
return nil
}
func (self *ConfirmationController) copyToClipboardEnabled() *types.DisabledReason {
if self.c.Views().Confirmation.Editable {
// The empty text is intentional. We don't want to get a toast when invoking this, we only
// want to prevent it from showing up in the options bar.
return &types.DisabledReason{Text: ""}
}
return nil
}