Просмотр исходного кода

fix: scroll to end of text on channel select (#85)

ayntgl 4 лет назад
Родитель
Сommit
cfee278be8
2 измененных файлов с 4 добавлено и 1 удалено
  1. 2 0
      discord.go
  2. 2 1
      ui.go

+ 2 - 0
discord.go

@@ -80,6 +80,8 @@ func onSessionMessageCreate(_ *discordgo.Session, m *discordgo.MessageCreate) {
 	} else {
 		selectedChannel.Messages = append(selectedChannel.Messages, m.Message)
 		messagesView.Write(buildMessage(m.Message))
+		// Scroll to the end of the text after the message has been written to the TextView.
+		messagesView.ScrollToEnd()
 	}
 }
 

+ 2 - 1
ui.go

@@ -100,6 +100,8 @@ func onChannelsTreeSelected(n *tview.TreeNode) {
 				selectedChannel.Messages = append(selectedChannel.Messages, ms[i])
 				messagesView.Write(buildMessage(ms[i]))
 			}
+			// Scroll to the end of the text after the messages have been written to the TextView.
+			messagesView.ScrollToEnd()
 
 			if len(ms) != 0 && isUnread(c) {
 				session.ChannelMessageAck(c.ID, c.LastMessageID, "")
@@ -114,7 +116,6 @@ func newMessagesView() *tview.TextView {
 		SetRegions(true).
 		SetDynamicColors(true).
 		SetWordWrap(true).
-		ScrollToEnd().
 		SetChangedFunc(func() {
 			app.Draw()
 		}).