Merge remote-tracking branch 'julianuu/master'

This commit is contained in:
Tulir Asokan 2020-05-10 01:39:59 +03:00
commit 4e2cbf1e4f
4 changed files with 34 additions and 0 deletions

1
go.mod
View File

@ -16,6 +16,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-20200421031010-7c45b8673834
go.etcd.io/bbolt v1.3.4
golang.org/x/image v0.0.0-20200430140353-33d19683fad8
golang.org/x/net v0.0.0-20200505041828-1ed23360d12c

View File

@ -119,6 +119,7 @@ func NewCommandProcessor(parent *MainView) *CommandProcessor {
"react": cmdReact,
"download": cmdDownload,
"open": cmdOpen,
"copy": cmdCopy,
"sendevent": cmdSendEvent,
"msendevent": cmdMSendEvent,
"setstate": cmdSetState,

View File

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

View File

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