From 0573529f8a56c93a6616dc4cebfd6f1dd18af379 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 15 Aug 2025 11:12:45 +0200 Subject: [PATCH 1/3] Cleanup: remove unnecessary code in test This was needed in an earlier version of the test, when we asserted the file content in a more complicated way. It should have been removed in caca62b89ef. --- pkg/integration/tests/misc/copy_to_clipboard.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pkg/integration/tests/misc/copy_to_clipboard.go b/pkg/integration/tests/misc/copy_to_clipboard.go index 5b4eb731d..594925614 100644 --- a/pkg/integration/tests/misc/copy_to_clipboard.go +++ b/pkg/integration/tests/misc/copy_to_clipboard.go @@ -29,11 +29,6 @@ var CopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{ t.ExpectToast(Equals("'branch-a' copied to clipboard")) - t.Views().Files(). - Focus() - - t.GlobalPress(keys.Files.RefreshFiles) - t.FileSystem().FileContent("clipboard", Equals("branch-a")) }, }) From 3fa5a8eddd4644f6b0f7e2b9244a9cdd2c120c42 Mon Sep 17 00:00:00 2001 From: kyu08 <49891479+kyu08@users.noreply.github.com> Date: Sun, 10 Aug 2025 19:04:00 +0900 Subject: [PATCH 2/3] Add "CopyToClipboard" command to `ConfirmationController` --- .../controllers/confirmation_controller.go | 27 +++++++++++++ pkg/i18n/english.go | 2 + pkg/integration/components/popup.go | 5 +++ .../copy_confirmation_message_to_clipboard.go | 40 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 5 files changed, 75 insertions(+) create mode 100644 pkg/integration/tests/misc/copy_confirmation_message_to_clipboard.go diff --git a/pkg/gui/controllers/confirmation_controller.go b/pkg/gui/controllers/confirmation_controller.go index 97754655f..1e4e5cd46 100644 --- a/pkg/gui/controllers/confirmation_controller.go +++ b/pkg/gui/controllers/confirmation_controller.go @@ -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 +} diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 24e428142..ee3c11dea 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -723,6 +723,7 @@ type TranslationSet struct { CommitHasNoTags string CommitHasNoMessageBody string PatchCopiedToClipboard string + MessageCopiedToClipboard string CopiedToClipboard string ErrCannotEditDirectory string ErrCannotCopyContentOfDirectory string @@ -1800,6 +1801,7 @@ func EnglishTranslationSet() *TranslationSet { CommitHasNoTags: "Commit has no tags", CommitHasNoMessageBody: "Commit has no message body", PatchCopiedToClipboard: "Patch copied to clipboard", + MessageCopiedToClipboard: "Message copied to clipboard", CopiedToClipboard: "copied to clipboard", ErrCannotEditDirectory: "Cannot edit directories: you can only edit individual files", ErrCannotCopyContentOfDirectory: "Cannot copy content of directories: you can only copy content of individual files", diff --git a/pkg/integration/components/popup.go b/pkg/integration/components/popup.go index 46df83e23..aa80770b2 100644 --- a/pkg/integration/components/popup.go +++ b/pkg/integration/components/popup.go @@ -36,6 +36,11 @@ func (self *Popup) Alert() *AlertDriver { return &AlertDriver{t: self.t} } +func (self *AlertDriver) Tap(f func()) *AlertDriver { + self.getViewDriver().Tap(f) + return self +} + func (self *Popup) inAlert() { // basically the same thing as a confirmation popup with the current implementation self.t.assertWithRetries(func() (bool, string) { diff --git a/pkg/integration/tests/misc/copy_confirmation_message_to_clipboard.go b/pkg/integration/tests/misc/copy_confirmation_message_to_clipboard.go new file mode 100644 index 000000000..6d98f856a --- /dev/null +++ b/pkg/integration/tests/misc/copy_confirmation_message_to_clipboard.go @@ -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)?")) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 000b21339..3fc314d10 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -299,6 +299,7 @@ var tests = []*components.IntegrationTest{ interactive_rebase.SwapWithConflict, interactive_rebase.ViewFilesOfTodoEntries, misc.ConfirmOnQuit, + misc.CopyConfirmationMessageToClipboard, misc.CopyToClipboard, misc.DisabledKeybindings, misc.InitialOpen, From fc84b77db8b21a23e7e46c5d93d461fb1724b592 Mon Sep 17 00:00:00 2001 From: kyu08 <49891479+kyu08@users.noreply.github.com> Date: Sun, 10 Aug 2025 19:47:41 +0900 Subject: [PATCH 3/3] Run `go generate ./...` --- docs/keybindings/Keybindings_en.md | 1 + docs/keybindings/Keybindings_ja.md | 1 + docs/keybindings/Keybindings_ko.md | 1 + docs/keybindings/Keybindings_nl.md | 1 + docs/keybindings/Keybindings_pl.md | 1 + docs/keybindings/Keybindings_pt.md | 1 + docs/keybindings/Keybindings_ru.md | 1 + docs/keybindings/Keybindings_zh-CN.md | 1 + docs/keybindings/Keybindings_zh-TW.md | 1 + 9 files changed, 9 insertions(+) diff --git a/docs/keybindings/Keybindings_en.md b/docs/keybindings/Keybindings_en.md index 2154880e6..f759f093d 100644 --- a/docs/keybindings/Keybindings_en.md +++ b/docs/keybindings/Keybindings_en.md @@ -125,6 +125,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ |-----|--------|-------------| | `` `` | Confirm | | | `` `` | Close/Cancel | | +| `` `` | Copy to clipboard | | ## Files diff --git a/docs/keybindings/Keybindings_ja.md b/docs/keybindings/Keybindings_ja.md index 490b0f36d..76d269ea5 100644 --- a/docs/keybindings/Keybindings_ja.md +++ b/docs/keybindings/Keybindings_ja.md @@ -402,3 +402,4 @@ _凡例:`<c-b>` はctrl+b、`<a-b>` はalt+b、`B` はshift+bを意味 |-----|--------|-------------| | `` `` | 確認 | | | `` `` | 閉じる/キャンセル | | +| `` `` | クリップボードにコピー | | diff --git a/docs/keybindings/Keybindings_ko.md b/docs/keybindings/Keybindings_ko.md index ac6d5fb03..a97fda889 100644 --- a/docs/keybindings/Keybindings_ko.md +++ b/docs/keybindings/Keybindings_ko.md @@ -402,3 +402,4 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ |-----|--------|-------------| | `` `` | 확인 | | | `` `` | 닫기/취소 | | +| `` `` | 클립보드에 복사 | | diff --git a/docs/keybindings/Keybindings_nl.md b/docs/keybindings/Keybindings_nl.md index 5ef08427a..37482fb74 100644 --- a/docs/keybindings/Keybindings_nl.md +++ b/docs/keybindings/Keybindings_nl.md @@ -91,6 +91,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ |-----|--------|-------------| | `` `` | Bevestig | | | `` `` | Sluiten | | +| `` `` | Copy to clipboard | | ## Branches diff --git a/docs/keybindings/Keybindings_pl.md b/docs/keybindings/Keybindings_pl.md index 52c6d666c..6595f2f3c 100644 --- a/docs/keybindings/Keybindings_pl.md +++ b/docs/keybindings/Keybindings_pl.md @@ -217,6 +217,7 @@ _Legenda: `` oznacza ctrl+b, `` oznacza alt+b, `B` oznacza shift+b_ |-----|--------|-------------| | `` `` | Potwierdź | | | `` `` | Zamknij/Anuluj | | +| `` `` | Kopiuj do schowka | | ## Pliki diff --git a/docs/keybindings/Keybindings_pt.md b/docs/keybindings/Keybindings_pt.md index 3c323f489..9eac7beb0 100644 --- a/docs/keybindings/Keybindings_pt.md +++ b/docs/keybindings/Keybindings_pt.md @@ -200,6 +200,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ |-----|--------|-------------| | `` `` | Confirmar | | | `` `` | Fechar/Cancelar | | +| `` `` | Copy to clipboard | | ## Etiquetas diff --git a/docs/keybindings/Keybindings_ru.md b/docs/keybindings/Keybindings_ru.md index 05749d5d9..753d74c36 100644 --- a/docs/keybindings/Keybindings_ru.md +++ b/docs/keybindings/Keybindings_ru.md @@ -237,6 +237,7 @@ _Связки клавиш_ |-----|--------|-------------| | `` `` | Подтвердить | | | `` `` | Закрыть/отменить | | +| `` `` | Copy to clipboard | | ## Подкоммиты diff --git a/docs/keybindings/Keybindings_zh-CN.md b/docs/keybindings/Keybindings_zh-CN.md index bfc09bfa4..185a6abb4 100644 --- a/docs/keybindings/Keybindings_zh-CN.md +++ b/docs/keybindings/Keybindings_zh-CN.md @@ -350,6 +350,7 @@ _图例:`` 意味着ctrl+b, `意味着Alt+b, `B` 意味着shift+b_ |-----|--------|-------------| | `` `` | 确认 | | | `` `` | 关闭 | | +| `` `` | 复制到剪贴板 | | ## 菜单 diff --git a/docs/keybindings/Keybindings_zh-TW.md b/docs/keybindings/Keybindings_zh-TW.md index 56ae29243..b91243c74 100644 --- a/docs/keybindings/Keybindings_zh-TW.md +++ b/docs/keybindings/Keybindings_zh-TW.md @@ -372,6 +372,7 @@ _說明:`` 表示 Ctrl+B、`` 表示 Alt+B,`B`表示 Shift+B |-----|--------|-------------| | `` `` | 確認 | | | `` `` | 關閉/取消 | | +| `` `` | 複製到剪貼簿 | | ## 遠端