diff options
| author | Kyren223 <Kyren223@proton.me> | 2024-12-23 20:16:11 +0200 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2024-12-23 20:16:11 +0200 |
| commit | f49f48d17bd50fe36ef08fdd4dff20e4cbb7e4f9 (patch) | |
| tree | 5316fefabb1d057515d2eaf8e092b8f87d804435 /internal | |
| parent | d87c6090d4a5ff658b0a6e4010c20b6c6a36119f (diff) | |
Improved scrolling by adding a blank line between message groups,
but skipping the bottom line when selecting for better UX and selecting
while not in "SnapToBottom" will now start from the bottom of the
screen, not the last message
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/client/ui/core/chat/chat.go | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/internal/client/ui/core/chat/chat.go b/internal/client/ui/core/chat/chat.go index 236022b..396622b 100644 --- a/internal/client/ui/core/chat/chat.go +++ b/internal/client/ui/core/chat/chat.go @@ -160,14 +160,19 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.vi.SetMode(viminput.InsertMode) m.index = -1 case "k": - // TODO: if not snap to bottom and -1 then do offset - lastHeight - m.index++ - maxHeight := m.offset - if m.offset == SnapToBottom { - maxHeight = m.messagesHeight - } - if m.index == maxHeight-1 { - m.offset = maxHeight + 1 + if m.index == -1 && m.offset != SnapToBottom { + m.index = m.offset - m.messagesHeight + } else if m.index == -1{ + m.index = 1 // Skip bottom blank line + } else { + m.index++ + maxHeight := m.offset + if m.offset == SnapToBottom { + maxHeight = m.messagesHeight + } + if m.index == maxHeight-1 { + m.offset = maxHeight + 1 + } } case "j": m.index = max(-1, m.index-1) @@ -177,7 +182,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.offset -= diff } } - if m.index <= 0 { + if m.index <= 1 { m.offset = SnapToBottom } } @@ -211,6 +216,7 @@ func (m *Model) sendMessage() tea.Cmd { } m.vi.Reset() + m.offset = SnapToBottom var receiverId *snowflake.ID = nil if m.receiverIndex != -1 { @@ -489,13 +495,13 @@ func (m *Model) renderMessageGroup(group []data.Message, remaining *int, height bottom := height - *remaining top := bottom + h *remaining -= h - if bottom <= m.index && m.index <= top { + if bottom < m.index && m.index <= top { selectedIndex = i } } - // buf = append(buf, '\n') // Gap between each message group - // *remaining-- // For gap - *remaining-- // For the header + *remaining-- // For the header + buf = append(buf, '\n') // Gap between each message group + *remaining-- // For gap if selectedIndex != -1 { if selectedIndex == len(group)-1 { @@ -515,7 +521,7 @@ func (m *Model) renderMessageGroup(group []data.Message, remaining *int, height buf = append(buf, content...) buf = append(buf, '\n') } - // buf = append(buf, '\n') // Gap between each message group + buf = append(buf, '\n') // Gap between each message group } return string(buf) |
