Skip to content

Commit 011ff85

Browse files
authored
Add "CopyToClipboard" command to ConfirmationController (#4810)
## **PR Description** Sometimes, I want to copy the error message to clipboard to search google or ask to LLM about the error message. So I added CopyToClipboard command to `ConfirmationController` and I have confirmed that this command copies the content of the window to the clipboard.
2 parents deaa701 + fc84b77 commit 011ff85

15 files changed

+84
-5
lines changed

docs/keybindings/Keybindings_en.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
125125
|-----|--------|-------------|
126126
| `` <enter> `` | Confirm | |
127127
| `` <esc> `` | Close/Cancel | |
128+
| `` <c-o> `` | Copy to clipboard | |
128129

129130
## Files
130131

docs/keybindings/Keybindings_ja.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,4 @@ _凡例:`<c-b>` はctrl+b、`<a-b>` はalt+b、`B` はshift+bを意味
402402
|-----|--------|-------------|
403403
| `` <enter> `` | 確認 | |
404404
| `` <esc> `` | 閉じる/キャンセル | |
405+
| `` <c-o> `` | クリップボードにコピー | |

docs/keybindings/Keybindings_ko.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,4 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
402402
|-----|--------|-------------|
403403
| `` <enter> `` | 확인 | |
404404
| `` <esc> `` | 닫기/취소 | |
405+
| `` <c-o> `` | 클립보드에 복사 | |

docs/keybindings/Keybindings_nl.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
9191
|-----|--------|-------------|
9292
| `` <enter> `` | Bevestig | |
9393
| `` <esc> `` | Sluiten | |
94+
| `` <c-o> `` | Copy to clipboard | |
9495

9596
## Branches
9697

docs/keybindings/Keybindings_pl.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ _Legenda: `<c-b>` oznacza ctrl+b, `<a-b>` oznacza alt+b, `B` oznacza shift+b_
217217
|-----|--------|-------------|
218218
| `` <enter> `` | Potwierdź | |
219219
| `` <esc> `` | Zamknij/Anuluj | |
220+
| `` <c-o> `` | Kopiuj do schowka | |
220221

221222
## Pliki
222223

docs/keybindings/Keybindings_pt.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
200200
|-----|--------|-------------|
201201
| `` <enter> `` | Confirmar | |
202202
| `` <esc> `` | Fechar/Cancelar | |
203+
| `` <c-o> `` | Copy to clipboard | |
203204

204205
## Etiquetas
205206

docs/keybindings/Keybindings_ru.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ _Связки клавиш_
237237
|-----|--------|-------------|
238238
| `` <enter> `` | Подтвердить | |
239239
| `` <esc> `` | Закрыть/отменить | |
240+
| `` <c-o> `` | Copy to clipboard | |
240241

241242
## Подкоммиты
242243

docs/keybindings/Keybindings_zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ _图例:`<c-b>` 意味着ctrl+b, `<a-b>意味着Alt+b, `B` 意味着shift+b_
350350
|-----|--------|-------------|
351351
| `` <enter> `` | 确认 | |
352352
| `` <esc> `` | 关闭 | |
353+
| `` <c-o> `` | 复制到剪贴板 | |
353354

354355
## 菜单
355356

docs/keybindings/Keybindings_zh-TW.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ _說明:`<c-b>` 表示 Ctrl+B、`<a-b>` 表示 Alt+B,`B`表示 Shift+B
372372
|-----|--------|-------------|
373373
| `` <enter> `` | 確認 | |
374374
| `` <esc> `` | 關閉/取消 | |
375+
| `` <c-o> `` | 複製到剪貼簿 | |
375376

376377
## 遠端
377378

pkg/gui/controllers/confirmation_controller.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ func (self *ConfirmationController) GetKeybindings(opts types.KeybindingsOpts) [
4747
return nil
4848
},
4949
},
50+
{
51+
Key: opts.GetKey(opts.Config.Universal.CopyToClipboard),
52+
Handler: self.handleCopyToClipboard,
53+
Description: self.c.Tr.CopyToClipboardMenu,
54+
DisplayOnScreen: true,
55+
GetDisabledReason: self.copyToClipboardEnabled,
56+
},
5057
}
5158

5259
return bindings
@@ -93,3 +100,23 @@ func (self *ConfirmationController) switchToSuggestions() {
93100
self.c.Views().Suggestions.Subtitle = subtitle
94101
self.c.Context().Replace(self.c.Contexts().Suggestions)
95102
}
103+
104+
func (self *ConfirmationController) handleCopyToClipboard() error {
105+
confirmationView := self.c.Views().Confirmation
106+
text := confirmationView.Buffer()
107+
if err := self.c.OS().CopyToClipboard(text); err != nil {
108+
return err
109+
}
110+
111+
self.c.Toast(self.c.Tr.MessageCopiedToClipboard)
112+
return nil
113+
}
114+
115+
func (self *ConfirmationController) copyToClipboardEnabled() *types.DisabledReason {
116+
if self.c.Views().Confirmation.Editable {
117+
// The empty text is intentional. We don't want to get a toast when invoking this, we only
118+
// want to prevent it from showing up in the options bar.
119+
return &types.DisabledReason{Text: ""}
120+
}
121+
return nil
122+
}

0 commit comments

Comments
 (0)