aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2020-05-10 01:39:59 +0300
committerTulir Asokan <tulir@maunium.net>2020-05-10 01:39:59 +0300
commit4e2cbf1e4fc40fb5c78c32567a0622a6ce63eeba (patch)
treea5b9f273722c1ff712ac328f58298c2f37668e32 /ui
parentf9007ae875d8f10e30f010414bc8bf2f9390de13 (diff)
parent12fb6c9076d0f70ef38f104e2bcf703084d85373 (diff)
Merge remote-tracking branch 'julianuu/master'
Diffstat (limited to 'ui')
-rw-r--r--ui/command-processor.go1
-rw-r--r--ui/commands.go13
-rw-r--r--ui/room-view.go19
3 files changed, 33 insertions, 0 deletions
diff --git a/ui/command-processor.go b/ui/command-processor.go
index 7a67d77..94b07b8 100644
--- a/ui/command-processor.go
+++ b/ui/command-processor.go
@@ -119,6 +119,7 @@ func NewCommandProcessor(parent *MainView) *CommandProcessor {
"react": cmdReact,
"download": cmdDownload,
"open": cmdOpen,
+ "copy": cmdCopy,
"sendevent": cmdSendEvent,
"msendevent": cmdMSendEvent,
"setstate": cmdSetState,
diff --git a/ui/commands.go b/ui/commands.go
index 961be26..fc86e85 100644
--- a/ui/commands.go
+++ b/ui/commands.go
@@ -158,6 +158,7 @@ const (
SelectRedact = "redact"
SelectDownload = "download"
SelectOpen = "open"
+ SelectCopy = "copy"
)
func cmdReply(cmd *Command) {
@@ -176,6 +177,18 @@ func cmdOpen(cmd *Command) {
cmd.Room.StartSelecting(SelectOpen, strings.Join(cmd.Args, " "))
}
+func cmdCopy(cmd *Command) {
+ register := strings.Join(cmd.Args, " ")
+ if len(register) == 0 {
+ register = "clipboard"
+ }
+ if (register == "clipboard" || register == "primary") {
+ cmd.Room.StartSelecting(SelectCopy, register)
+ } else {
+ cmd.Reply("Usage: /copy [register], where register is either \"clipboard\" or \"primary\". Defaults to \"clipboard\".")
+ }
+}
+
func cmdReact(cmd *Command) {
if len(cmd.Args) == 0 {
cmd.Reply("Usage: /react <reaction>")
diff --git a/ui/room-view.go b/ui/room-view.go
index 09e1965..dbdaccc 100644
--- a/ui/room-view.go
+++ b/ui/room-view.go
@@ -25,6 +25,7 @@ import (
"github.com/kyokomi/emoji"
"github.com/mattn/go-runewidth"
+ "github.com/zyedidia/clipboard"
"maunium.net/go/mautrix/crypto/attachment"
"maunium.net/go/mauview"
@@ -209,6 +210,11 @@ func (view *RoomView) OnSelect(message *messages.UIMessage) {
}
go view.Download(msg.URL, msg.File, path, view.selectReason == SelectOpen)
}
+ case SelectCopy:
+ msg, ok := message.Renderer.(*messages.TextMessage)
+ if ok {
+ go view.CopyToClipboard(msg.PlainText(), view.selectContent)
+ }
}
view.selecting = false
view.selectContent = ""
@@ -629,6 +635,19 @@ func (view *RoomView) InputSubmit(text string) {
view.SetInputText("")
}
+func (view *RoomView) CopyToClipboard(text string, register string) {
+ if register == "clipboard" || register == "primary" {
+ err := clipboard.WriteAll(text, register)
+ if err != nil {
+ view.AddServiceMessage(fmt.Sprintf("Clipboard unsupported: %v", err))
+ view.parent.parent.Render()
+ }
+ } else {
+ view.AddServiceMessage(fmt.Sprintf("Clipboard register %v unsupported", register))
+ view.parent.parent.Render()
+ }
+}
+
func (view *RoomView) Download(url id.ContentURI, file *attachment.EncryptedFile, filename string, openFile bool) {
path, err := view.parent.matrix.DownloadToDisk(url, file, filename)
if err != nil {