aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2020-02-21 00:29:29 +0200
committerTulir Asokan <tulir@maunium.net>2020-02-21 00:29:29 +0200
commit032a83d70bec5b87605e04c755c678ec01a0de11 (patch)
treeedd0fbb85ca7eaa7fffbe91a1a3b1c6c94585bee /ui
parent98dd1bcdc9f55e94e81064ac435369f4396038f3 (diff)
Add initial message selecting stuff
Diffstat (limited to 'ui')
-rw-r--r--ui/message-view.go29
-rw-r--r--ui/messages/base.go13
2 files changed, 33 insertions, 9 deletions
diff --git a/ui/message-view.go b/ui/message-view.go
index 20ee149..e079407 100644
--- a/ui/message-view.go
+++ b/ui/message-view.go
@@ -64,6 +64,7 @@ type MessageView struct {
messages []*messages.UIMessage
msgBufferLock sync.RWMutex
msgBuffer []*messages.UIMessage
+ selected *messages.UIMessage
initialHistoryLoaded bool
}
@@ -286,12 +287,12 @@ func (view *MessageView) replaceBuffer(original *messages.UIMessage, new *messag
if new.Height() != end-start {
height := new.Height()
- newBuffer := make([]*messages.UIMessage, height + len(view.msgBuffer) - end)
+ newBuffer := make([]*messages.UIMessage, height+len(view.msgBuffer)-end)
for i := 0; i < height; i++ {
newBuffer[i] = new
}
for i := height; i < len(newBuffer); i++ {
- newBuffer[i] = view.msgBuffer[end + (i - height)]
+ newBuffer[i] = view.msgBuffer[end+(i-height)]
}
view.msgBuffer = append(view.msgBuffer[0:start], newBuffer...)
} else {
@@ -333,14 +334,24 @@ func (view *MessageView) recalculateBuffers() {
view.prevPrefs = prefs
}
-func (view *MessageView) handleMessageClick(message *messages.UIMessage) bool {
- switch msg := message.Renderer.(type) {
- case *messages.ImageMessage:
+func (view *MessageView) SetSelected(message *messages.UIMessage) {
+ if view.selected != nil {
+ view.selected.IsSelected = false
+ }
+ view.selected = message
+ if view.selected != nil {
+ view.selected.IsSelected = true
+ }
+}
+
+func (view *MessageView) handleMessageClick(message *messages.UIMessage, mod tcell.ModMask) bool {
+ if msg, ok := message.Renderer.(*messages.ImageMessage); ok && mod > 0 {
open.Open(msg.Path())
- default:
- debug.Print("Message clicked:", message)
+ // No need to re-render
+ return false
}
- return false
+ view.SetSelected(message)
+ return true
}
func (view *MessageView) handleUsernameClick(message *messages.UIMessage, prevMessage *messages.UIMessage) bool {
@@ -410,7 +421,7 @@ func (view *MessageView) OnMouseEvent(event mauview.MouseEvent) bool {
messageX := usernameX + view.widestSender() + SenderMessageGap
if x >= messageX {
- return view.handleMessageClick(message)
+ return view.handleMessageClick(message, event.Modifiers())
} else if x >= usernameX {
return view.handleUsernameClick(message, prevMessage)
}
diff --git a/ui/messages/base.go b/ui/messages/base.go
index 0c9025e..4d82b00 100644
--- a/ui/messages/base.go
+++ b/ui/messages/base.go
@@ -77,6 +77,7 @@ type UIMessage struct {
State event.OutgoingState
IsHighlight bool
IsService bool
+ IsSelected bool
Edited bool
Event *event.Event
ReplyTo *UIMessage
@@ -316,6 +317,18 @@ func (msg *UIMessage) Draw(screen mauview.Screen) {
screen = msg.DrawReply(screen)
msg.Renderer.Draw(screen)
msg.DrawReactions(screen)
+ if msg.IsSelected {
+ w, h := screen.Size()
+ for x := 0; x < w; x++ {
+ for y := 0; y < h; y++ {
+ mainc, combc, style, _ := screen.GetContent(x, y)
+ _, bg, _ := style.Decompose()
+ if bg == tcell.ColorDefault {
+ screen.SetContent(x, y, mainc, combc, style.Background(tcell.ColorLightSkyBlue))
+ }
+ }
+ }
+ }
}
func (msg *UIMessage) Clone() *UIMessage {