Browse Source

fix: highlight messages using mouse (#441)

Thomas Baag 1 year ago
parent
commit
54c55eb69b
1 changed files with 14 additions and 0 deletions
  1. 14 0
      cmd/messages_text.go

+ 14 - 0
cmd/messages_text.go

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