mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-24 19:39:16 +02:00
Add "CopyToClipboard" command to ConfirmationController
This commit is contained in:
@@ -47,6 +47,13 @@ func (self *ConfirmationController) GetKeybindings(opts types.KeybindingsOpts) [
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Universal.CopyToClipboard),
|
||||||
|
Handler: self.handleCopyToClipboard,
|
||||||
|
Description: self.c.Tr.CopyToClipboardMenu,
|
||||||
|
DisplayOnScreen: true,
|
||||||
|
GetDisabledReason: self.copyToClipboardEnabled,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return bindings
|
return bindings
|
||||||
@@ -93,3 +100,23 @@ func (self *ConfirmationController) switchToSuggestions() {
|
|||||||
self.c.Views().Suggestions.Subtitle = subtitle
|
self.c.Views().Suggestions.Subtitle = subtitle
|
||||||
self.c.Context().Replace(self.c.Contexts().Suggestions)
|
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
|
||||||
|
}
|
||||||
|
@@ -723,6 +723,7 @@ type TranslationSet struct {
|
|||||||
CommitHasNoTags string
|
CommitHasNoTags string
|
||||||
CommitHasNoMessageBody string
|
CommitHasNoMessageBody string
|
||||||
PatchCopiedToClipboard string
|
PatchCopiedToClipboard string
|
||||||
|
MessageCopiedToClipboard string
|
||||||
CopiedToClipboard string
|
CopiedToClipboard string
|
||||||
ErrCannotEditDirectory string
|
ErrCannotEditDirectory string
|
||||||
ErrCannotCopyContentOfDirectory string
|
ErrCannotCopyContentOfDirectory string
|
||||||
@@ -1800,6 +1801,7 @@ func EnglishTranslationSet() *TranslationSet {
|
|||||||
CommitHasNoTags: "Commit has no tags",
|
CommitHasNoTags: "Commit has no tags",
|
||||||
CommitHasNoMessageBody: "Commit has no message body",
|
CommitHasNoMessageBody: "Commit has no message body",
|
||||||
PatchCopiedToClipboard: "Patch copied to clipboard",
|
PatchCopiedToClipboard: "Patch copied to clipboard",
|
||||||
|
MessageCopiedToClipboard: "Message copied to clipboard",
|
||||||
CopiedToClipboard: "copied to clipboard",
|
CopiedToClipboard: "copied to clipboard",
|
||||||
ErrCannotEditDirectory: "Cannot edit directories: you can only edit individual files",
|
ErrCannotEditDirectory: "Cannot edit directories: you can only edit individual files",
|
||||||
ErrCannotCopyContentOfDirectory: "Cannot copy content of directories: you can only copy content of individual files",
|
ErrCannotCopyContentOfDirectory: "Cannot copy content of directories: you can only copy content of individual files",
|
||||||
|
@@ -36,6 +36,11 @@ func (self *Popup) Alert() *AlertDriver {
|
|||||||
return &AlertDriver{t: self.t}
|
return &AlertDriver{t: self.t}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *AlertDriver) Tap(f func()) *AlertDriver {
|
||||||
|
self.getViewDriver().Tap(f)
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
func (self *Popup) inAlert() {
|
func (self *Popup) inAlert() {
|
||||||
// basically the same thing as a confirmation popup with the current implementation
|
// basically the same thing as a confirmation popup with the current implementation
|
||||||
self.t.assertWithRetries(func() (bool, string) {
|
self.t.assertWithRetries(func() (bool, string) {
|
||||||
|
@@ -0,0 +1,40 @@
|
|||||||
|
package misc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||||
|
)
|
||||||
|
|
||||||
|
var CopyConfirmationMessageToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
|
Description: "Copy the text of a confirmation popup to the clipboard",
|
||||||
|
ExtraCmdArgs: []string{},
|
||||||
|
Skip: false,
|
||||||
|
SetupConfig: func(config *config.AppConfig) {
|
||||||
|
config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > clipboard"
|
||||||
|
},
|
||||||
|
|
||||||
|
SetupRepo: func(shell *Shell) {
|
||||||
|
shell.EmptyCommit("commit")
|
||||||
|
},
|
||||||
|
|
||||||
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
|
t.Views().Commits().
|
||||||
|
Focus().
|
||||||
|
Lines(
|
||||||
|
Contains("commit").IsSelected(),
|
||||||
|
).
|
||||||
|
Press(keys.Universal.Remove)
|
||||||
|
|
||||||
|
t.ExpectPopup().Alert().
|
||||||
|
Title(Equals("Drop commit")).
|
||||||
|
Content(Equals("Are you sure you want to drop the selected commit(s)?")).
|
||||||
|
Tap(func() {
|
||||||
|
t.GlobalPress(keys.Universal.CopyToClipboard)
|
||||||
|
t.ExpectToast(Equals("Message copied to clipboard"))
|
||||||
|
}).
|
||||||
|
Confirm()
|
||||||
|
|
||||||
|
t.FileSystem().FileContent("clipboard",
|
||||||
|
Equals("Are you sure you want to drop the selected commit(s)?"))
|
||||||
|
},
|
||||||
|
})
|
@@ -299,6 +299,7 @@ var tests = []*components.IntegrationTest{
|
|||||||
interactive_rebase.SwapWithConflict,
|
interactive_rebase.SwapWithConflict,
|
||||||
interactive_rebase.ViewFilesOfTodoEntries,
|
interactive_rebase.ViewFilesOfTodoEntries,
|
||||||
misc.ConfirmOnQuit,
|
misc.ConfirmOnQuit,
|
||||||
|
misc.CopyConfirmationMessageToClipboard,
|
||||||
misc.CopyToClipboard,
|
misc.CopyToClipboard,
|
||||||
misc.DisabledKeybindings,
|
misc.DisabledKeybindings,
|
||||||
misc.InitialOpen,
|
misc.InitialOpen,
|
||||||
|
Reference in New Issue
Block a user