Use github.com/zyedidia/clipboard for clipboard.

Now one can choose as register clipboard and primary.
This commit is contained in:
Julian Weigt 2020-04-26 22:19:41 +03:00
parent 0f85fcc3fa
commit b0983a47c9
3 changed files with 25 additions and 6 deletions

1
go.mod
View File

@ -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

View File

@ -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\".")
}
}

View File

@ -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 {