aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--go.mod1
-rw-r--r--ui/commands.go11
-rw-r--r--ui/room-view.go19
3 files changed, 25 insertions, 6 deletions
diff --git a/go.mod b/go.mod
index b8106b0..3ad5825 100644
--- a/go.mod
+++ b/go.mod
@@ -17,6 +17,7 @@ require (
github.com/sasha-s/go-deadlock v0.2.0
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/stretchr/testify v1.5.1
+ github.com/zyedidia/clipboard v0.0.0-20190823154308-241f98e9b197
go.etcd.io/bbolt v1.3.3
golang.org/x/image v0.0.0-20200119044424-58c23975cae1
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
diff --git a/ui/commands.go b/ui/commands.go
index 27c9caf..ed853a2 100644
--- a/ui/commands.go
+++ b/ui/commands.go
@@ -34,7 +34,6 @@ import (
"github.com/lucasb-eyer/go-colorful"
"github.com/russross/blackfriday/v2"
- "github.com/atotto/clipboard"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/event"
@@ -179,10 +178,14 @@ func cmdOpen(cmd *Command) {
}
func cmdCopy(cmd *Command) {
- if clipboard.Unsupported {
- cmd.Reply("Clipboard unsupported.")
+ register := strings.Join(cmd.Args, " ")
+ if len(register) == 0 {
+ register = "clipboard"
+ }
+ if (register == "clipboard" || register == "primary") {
+ cmd.Room.StartSelecting(SelectCopy, register)
} else {
- cmd.Room.StartSelecting(SelectCopy, strings.Join(cmd.Args, " "))
+ cmd.Reply("Usage: /copy [register], where register is either \"clipboard\" or \"primary\". Defaults to \"clipboard\".")
}
}
diff --git a/ui/room-view.go b/ui/room-view.go
index 641e9d1..e9523d9 100644
--- a/ui/room-view.go
+++ b/ui/room-view.go
@@ -25,7 +25,7 @@ import (
"github.com/kyokomi/emoji"
"github.com/mattn/go-runewidth"
- "github.com/atotto/clipboard"
+ "github.com/zyedidia/clipboard"
"maunium.net/go/mauview"
"maunium.net/go/tcell"
@@ -208,7 +208,7 @@ func (view *RoomView) OnSelect(message *messages.UIMessage) {
case SelectCopy:
msg, ok := message.Renderer.(*messages.TextMessage)
if ok {
- go clipboard.WriteAll(msg.PlainText())
+ go view.CopyToClipboard(msg.PlainText(),view.selectContent)
}
}
view.selecting = false
@@ -630,6 +630,21 @@ 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()
+ return
+ }
+ } else {
+ view.AddServiceMessage(fmt.Sprintf("Clipboard register %v unsupported", register))
+ view.parent.parent.Render()
+ return
+ }
+}
+
func (view *RoomView) Download(url id.ContentURI, filename string, openFile bool) {
path, err := view.parent.matrix.DownloadToDisk(url, filename)
if err != nil {