From f6eb3d665e75d59afdae62ccfac7e1719d54e1c4 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Tue, 24 Dec 2024 18:35:56 +0200 Subject: [PATCH] Scrolling beyond the first message is now impossible even when the screen is not filled with messages --- internal/client/ui/core/chat/chat.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/client/ui/core/chat/chat.go b/internal/client/ui/core/chat/chat.go index 286272e..c94db31 100644 --- a/internal/client/ui/core/chat/chat.go +++ b/internal/client/ui/core/chat/chat.go @@ -416,10 +416,12 @@ func (m *Model) renderMessages(screenHeight int) string { renderedGroup := m.renderMessageGroup(group, &remainingHeight, height) renderedGroups = append(renderedGroups, renderedGroup) - if remainingHeight > 0 && m.offset != SnapToBottom { + if remainingHeight > 0 { m.maxMessagesHeight = height - remainingHeight - m.offset = min(m.offset, m.maxMessagesHeight+1) - m.index = min(m.index, m.offset-2) + if m.offset != SnapToBottom { + m.offset = min(m.offset, m.maxMessagesHeight+1) + m.index = min(m.index, m.offset-2) + } } } @@ -608,6 +610,11 @@ func (m *Model) Scroll(amount int) { if amount > 0 { // Scrolling up + if m.offset == SnapToBottom && m.maxMessagesHeight != -1 { + m.index = min(m.index, m.maxMessagesHeight-1) + return + } + maxHeight := m.offset if m.offset == SnapToBottom { maxHeight = m.messagesHeight