From 19de9a1ba2cba8ec6b62fbd5fbe40f51effb6243 Mon Sep 17 00:00:00 2001 From: ayn2op Date: Mon, 9 Jan 2023 15:44:12 +0530 Subject: [PATCH] paste --- config.go | 8 ++++++-- message_input.go | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index 2fedd45..422083e 100644 --- a/config.go +++ b/config.go @@ -24,7 +24,9 @@ type ( } MessageInputKeysConfig struct { - Send string `yaml:"send"` + Send string `yaml:"send"` + Paste string `yaml:"paste"` + LaunchEditor string `yaml:"launch_editor"` } @@ -104,7 +106,9 @@ func newConfig() (*Config, error) { SelectLast: "End", }, MessageInput: MessageInputKeysConfig{ - Send: "Enter", + Send: "Enter", + + Paste: "Ctrl+V", LaunchEditor: "Ctrl+E", }, }, diff --git a/message_input.go b/message_input.go index 913a9de..5eadabb 100644 --- a/message_input.go +++ b/message_input.go @@ -6,6 +6,7 @@ import ( "os/exec" "strings" + "github.com/atotto/clipboard" "github.com/diamondburned/arikawa/v3/api" "github.com/diamondburned/arikawa/v3/discord" "github.com/diamondburned/arikawa/v3/utils/json/option" @@ -46,6 +47,9 @@ func (mi *MessageInput) onInputCapture(event *tcell.EventKey) *tcell.EventKey { case config.Keys.MessageInput.Send: mi.sendAction() return nil + case config.Keys.MessageInput.Paste: + mi.pasteAction() + return nil case config.Keys.MessageInput.LaunchEditor: messageInput.launchEditorAction() return nil @@ -100,6 +104,16 @@ func (mi *MessageInput) sendAction() { mi.reset() } +func (mi *MessageInput) pasteAction() { + text, err := clipboard.ReadAll() + if err != nil { + log.Fatal(err) + } + + // Append the text to the message input. + mi.SetText(mi.GetText() + text) +} + func (mi *MessageInput) launchEditorAction() { e := config.Editor if e == "default" {