diff options
| author | phantomreactor <[email protected]> | 2025-05-17 01:01:50 +0530 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-05-16 14:31:50 -0500 |
| commit | ba416e787b651ea045ff955eb32c0e7109a169e8 (patch) | |
| tree | 59133f1dca814bf11a183d9f59bd52e09c93a737 /internal/tui/components | |
| parent | b71cae63f1b59cc3f095912d040b915312d144ff (diff) | |
| download | opencode-ba416e787b651ea045ff955eb32c0e7109a169e8.tar.gz opencode-ba416e787b651ea045ff955eb32c0e7109a169e8.zip | |
paste images with ctrl+v (#26)
Diffstat (limited to 'internal/tui/components')
| -rw-r--r-- | internal/tui/components/chat/editor.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/tui/components/chat/editor.go b/internal/tui/components/chat/editor.go index 4d5ba0128..607aaedf3 100644 --- a/internal/tui/components/chat/editor.go +++ b/internal/tui/components/chat/editor.go @@ -2,6 +2,7 @@ package chat import ( "fmt" + "log/slog" "os" "os/exec" "slices" @@ -16,6 +17,7 @@ import ( "github.com/sst/opencode/internal/message" "github.com/sst/opencode/internal/status" "github.com/sst/opencode/internal/tui/components/dialog" + "github.com/sst/opencode/internal/tui/image" "github.com/sst/opencode/internal/tui/layout" "github.com/sst/opencode/internal/tui/styles" "github.com/sst/opencode/internal/tui/theme" @@ -34,6 +36,7 @@ type editorCmp struct { type EditorKeyMaps struct { Send key.Binding OpenEditor key.Binding + Paste key.Binding } type bluredEditorKeyMaps struct { @@ -56,6 +59,10 @@ var editorMaps = EditorKeyMaps{ key.WithKeys("ctrl+e"), key.WithHelp("ctrl+e", "open editor"), ), + Paste: key.NewBinding( + key.WithKeys("ctrl+v"), + key.WithHelp("ctrl+v", "paste content"), + ), } var DeleteKeyMaps = DeleteAttachmentKeyMaps{ @@ -200,6 +207,22 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.deleteMode = false return m, nil } + + if key.Matches(msg, editorMaps.Paste) { + imageBytes, text, err := image.GetImageFromClipboard() + if err != nil { + slog.Error(err.Error()) + return m, cmd + } + if len(imageBytes) != 0 { + attachmentName := fmt.Sprintf("clipboard-image-%d", len(m.attachments)) + attachment := message.Attachment{FilePath: attachmentName, FileName: attachmentName, Content: imageBytes, MimeType: "image/png"} + m.attachments = append(m.attachments, attachment) + } else { + m.textarea.SetValue(m.textarea.Value() + text) + } + return m, cmd + } // Handle Enter key if m.textarea.Focused() && key.Matches(msg, editorMaps.Send) { value := m.textarea.Value() |
