Initial implementation of image paste
MODIFY
internal/ui/editor.go
internal/ui/editor.go
@@ -5,9 +5,8 @@ import (
"regexp"
"strings"
- "github.com/atotto/clipboard"
-
"github.com/Bios-Marcel/tview"
+ "github.com/atotto/clipboard"
"github.com/gdamore/tcell"
)
@@ -235,7 +234,22 @@ func NewEditor() *Editor {
newText = newText + endRegion
editor.setAndFixText(newText)
}
- } else if event.Key() == tcell.KeyCtrlV {
+ } else {
+ var character rune
+ if event.Key() == tcell.KeyEnter {
+ if (event.Modifiers() & tcell.ModAlt) == tcell.ModAlt {
+ character = '\n'
+ }
+ } else {
+ character = event.Rune()
+ }
+
+ if event.Key() == tcell.KeyCtrlV {
+ result := editor.inputCapture(event)
+ if result == nil {
+ return nil
+ }
+
clipBoardContent, clipError := clipboard.ReadAll()
if clipError == nil {
if string(selection) == selectionChar {
@@ -257,14 +271,7 @@ func NewEditor() *Editor {
}
editor.setAndFixText(newText + endRegion)
}
- } else {
- var character rune
- if event.Key() == tcell.KeyEnter {
- if (event.Modifiers() & tcell.ModAlt) == tcell.ModAlt {
- character = '\n'
- }
- } else {
- character = event.Rune()
+ return nil
}
if character == 0 {

MODIFY
internal/ui/window.go
internal/ui/window.go
package ui
import (
+ "bytes"
"fmt"
"regexp"
"sort"
"strings"
"time"
+ "github.com/Bios-Marcel/goclipimg"
+
"github.com/atotto/clipboard"
"github.com/Bios-Marcel/cordless/internal/commands"
@@ -550,6 +553,23 @@ func NewWindow(app *tview.Application, discord *discordgo.Session) (*Window, err
return nil
}
+ if event.Key() == tcell.KeyCtrlV && window.selectedChannel != nil {
+ data, clipError := goclipimg.GetImageFromClipboard()
+ if clipError == nil {
+ dataChannel := bytes.NewReader(data)
+ currentText := window.messageInput.GetText()
+ if currentText == "" {
+ go window.session.ChannelFileSend(window.selectedChannel.ID, "img.png", dataChannel)
+ } else {
+ go window.session.ChannelFileSendWithMessage(window.selectedChannel.ID, currentText, "img.png", dataChannel)
+ window.messageInput.SetText("")
+ }
+ } else {
+ window.ShowErrorDialog(fmt.Sprintf("Error pasting image: %s", clipError.Error()))
+ }
+ return nil
+ }
+
if event.Key() == tcell.KeyEnter {
if window.selectedChannel != nil {
window.messageInput.SetText("")

Initial implementation of image paste