fix: highlight messages using mouse (#441)

This commit is contained in:
Thomas Baag 2024-09-25 10:11:11 +02:00 • committed by GitHub
parent 431c40f220
commit 54c55eb69b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,6 +6,7 @@ import (
"io"
"log/slog"
"slices"
"strconv"
"time"
"github.com/atotto/clipboard"
@ -55,6 +56,8 @@ func newMessagesText() *MessagesText {
renderer.WithOption("linkColor", cfg.Theme.MessagesText.LinkColor),
)
mt.SetHighlightedFunc(mt.onHighlighted)
return mt
}
@ -280,6 +283,17 @@ func (mt *MessagesText) _select(name string) {
mt.ScrollToHighlight()
}
func (mt *MessagesText) onHighlighted(added, removed, remaining []string) {
if (len(added) > 0) {
mID, err := strconv.ParseInt(added[0], 10, 64)
if err != nil {
slog.Error("Failed to parse region id as int to use as message id.","err",err)
return
}
mt.selectedMessageID = discord.MessageID(mID)
}
}
func (mt *MessagesText) yank() {
msg, err := mt.getSelectedMessage()
if err != nil {