aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ui/message-view.go70
-rw-r--r--ui/room-view.go2
-rw-r--r--ui/view-main.go4
3 files changed, 59 insertions, 17 deletions
diff --git a/ui/message-view.go b/ui/message-view.go
index 9216aed..80add59 100644
--- a/ui/message-view.go
+++ b/ui/message-view.go
@@ -22,19 +22,21 @@ import (
"math"
"os"
- "maunium.net/go/gomuks/lib/open"
- "maunium.net/go/gomuks/ui/messages/tstring"
- "maunium.net/go/tcell"
"maunium.net/go/gomuks/debug"
"maunium.net/go/gomuks/interface"
+ "maunium.net/go/gomuks/lib/open"
"maunium.net/go/gomuks/ui/messages"
+ "maunium.net/go/gomuks/ui/messages/tstring"
"maunium.net/go/gomuks/ui/widget"
+ "maunium.net/go/tcell"
"maunium.net/go/tview"
)
type MessageView struct {
*tview.Box
+ parent *RoomView
+
ScrollOffset int
MaxSenderWidth int
DateFormat string
@@ -54,9 +56,11 @@ type MessageView struct {
metaBuffer []ifc.MessageMeta
}
-func NewMessageView() *MessageView {
+func NewMessageView(parent *RoomView) *MessageView {
return &MessageView{
- Box: tview.NewBox(),
+ Box: tview.NewBox(),
+ parent: parent,
+
MaxSenderWidth: 15,
TimestampWidth: len(messages.TimeFormat),
ScrollOffset: 0,
@@ -253,28 +257,64 @@ func (view *MessageView) recalculateBuffers() {
}
}
-func (view *MessageView) HandleClick(x, y int, button tcell.ButtonMask) {
+func (view *MessageView) HandleClick(x, y int, button tcell.ButtonMask) bool {
if button != tcell.Button1 {
- return
+ return false
}
_, _, _, height := view.GetRect()
line := view.TotalHeight() - view.ScrollOffset - height + y
if line < 0 || line >= view.TotalHeight() {
- return
+ return false
}
message := view.metaBuffer[line]
- imageMessage, ok := message.(*messages.ImageMessage)
- if !ok {
+ var prevMessage ifc.MessageMeta
+ if line > 0 {
+ prevMessage = view.metaBuffer[line-1]
+ }
+
+ usernameX := view.TimestampWidth + TimestampSenderGap
+ messageX := usernameX + view.widestSender + SenderMessageGap
+ if x >= messageX {
+ switch message := message.(type) {
+ case *messages.ImageMessage:
+ open.Open(message.Path())
+ case messages.UIMessage:
+ debug.Print("Message clicked:", message.NotificationContent())
+ }
+ } else if x >= usernameX {
uiMessage, ok := message.(messages.UIMessage)
- if ok {
- debug.Print("Message clicked:", uiMessage.NotificationContent())
+ if !ok {
+ return false
+ }
+
+ prevUIMessage, _ := prevMessage.(messages.UIMessage)
+ if prevUIMessage != nil && prevUIMessage.Sender() == uiMessage.Sender() {
+ return false
+ }
+
+ sender := []rune(uiMessage.Sender())
+ if len(sender) == 0 {
+ return false
}
- return
- }
- open.Open(imageMessage.Path())
+ cursorPos := view.parent.input.GetCursorOffset()
+ text := []rune(view.parent.input.GetText())
+ var newText []rune
+ if cursorPos == 0 {
+ newText = append(sender, ':', ' ')
+ newText = append(newText, text...)
+ } else {
+ newText = append(text[0:cursorPos], sender...)
+ newText = append(newText, ' ')
+ newText = append(newText, text[cursorPos:]...)
+ }
+ view.parent.input.SetText(string(newText))
+ view.parent.input.SetCursorOffset(cursorPos + len(newText) - len(text))
+ return true
+ }
+ return false
}
const PaddingAtTop = 5
diff --git a/ui/room-view.go b/ui/room-view.go
index ba3b004..d7824fe 100644
--- a/ui/room-view.go
+++ b/ui/room-view.go
@@ -47,13 +47,13 @@ func NewRoomView(room *rooms.Room) *RoomView {
view := &RoomView{
Box: tview.NewBox(),
topic: tview.NewTextView(),
- content: NewMessageView(),
status: tview.NewTextView(),
userList: tview.NewTextView(),
ulBorder: widget.NewBorder(),
input: widget.NewAdvancedInputField(),
Room: room,
}
+ view.content = NewMessageView(view)
view.input.
SetFieldBackgroundColor(tcell.ColorDefault).
diff --git a/ui/view-main.go b/ui/view-main.go
index 50304fc..d4ffd39 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -248,7 +248,9 @@ func (view *MainView) MouseEventHandler(roomView *RoomView, event *tcell.EventMo
default:
mx, my, mw, mh := msgView.GetRect()
if x >= mx && y >= my && x < mx+mw && y < my+mh {
- msgView.HandleClick(x-mx, y-my, event.Buttons())
+ if msgView.HandleClick(x-mx, y-my, event.Buttons()) {
+ view.parent.Render()
+ }
} else {
debug.Print("Mouse event received:", event.Buttons(), event.Modifiers(), x, y)
}