diff options
| author | Kyren223 <Kyren223@proton.me> | 2024-12-23 18:43:07 +0200 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2024-12-23 18:43:07 +0200 |
| commit | 8e5a560f985f6c72e9109e25ecfd8bbc09540020 (patch) | |
| tree | 4d9ddc65aade23ace45805b46038392c9086241d /internal/client/ui/core/chat | |
| parent | 2b5b32fc4731bc478ed4e20b84c46ba302a5ff15 (diff) | |
Implemented basic scrolling, needs improvements
Diffstat (limited to 'internal/client/ui/core/chat')
| -rw-r--r-- | internal/client/ui/core/chat/chat.go | 38 |
1 files changed, 13 insertions, 25 deletions
diff --git a/internal/client/ui/core/chat/chat.go b/internal/client/ui/core/chat/chat.go index c0e92ea..236022b 100644 --- a/internal/client/ui/core/chat/chat.go +++ b/internal/client/ui/core/chat/chat.go @@ -166,15 +166,8 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { if m.offset == SnapToBottom { maxHeight = m.messagesHeight } - if m.index == maxHeight-2 { - log.Println("Index:", m.index, "Height:", m.messagesHeight) + if m.index == maxHeight-1 { m.offset = maxHeight + 1 - m.index-- - - // Max height is here - // Should be rendered up to here <- - // After add - // Here } case "j": m.index = max(-1, m.index-1) @@ -184,7 +177,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.offset -= diff } } - if m.offset == 0 { + if m.index <= 0 { m.offset = SnapToBottom } } @@ -364,7 +357,7 @@ func (m *Model) renderMessageBox() string { return lipgloss.NewStyle().Padding(0, PaddingCount).Render(result) } -func (m *Model) renderMessages(height int) string { +func (m *Model) renderMessages(screenHeight int) string { var btree *btree.BTreeG[data.Message] if m.frequencyIndex != -1 && m.networkIndex != -1 { network := state.State.Networks[m.networkIndex] @@ -375,13 +368,14 @@ func (m *Model) renderMessages(height int) string { } if btree == nil { - return NilBtreeError.Height(height).String() + return NilBtreeError.Height(screenHeight).String() } - remainingHeight := m.offset - if m.offset == SnapToBottom { - remainingHeight = height + height := screenHeight + if m.offset != SnapToBottom { + height = m.offset } + remainingHeight := height renderedGroups := []string{} group := []data.Message{} @@ -454,7 +448,7 @@ func (m *Model) renderMessages(height int) string { if newlines == m.offset && offsetIndex == -1 { offsetIndex = i } - if newlines == m.offset-height && upToIndex == -1 { + if newlines == m.offset-screenHeight+1 && upToIndex == -1 { upToIndex = i } if offsetIndex != -1 && upToIndex != -1 { @@ -499,11 +493,9 @@ func (m *Model) renderMessageGroup(group []data.Message, remaining *int, height selectedIndex = i } } - buf = append(buf, '\n') // Gap between each message group - *remaining-- // For gap - *remaining-- // For the header - - log.Println(selectedIndex) + // buf = append(buf, '\n') // Gap between each message group + // *remaining-- // For gap + *remaining-- // For the header if selectedIndex != -1 { if selectedIndex == len(group)-1 { @@ -520,14 +512,10 @@ func (m *Model) renderMessageGroup(group []data.Message, remaining *int, height // Redraw rest for i := selectedIndex - 1; i >= 0; i-- { content := messageStyle.Render(group[i].Content) - buf = append(buf, content...) buf = append(buf, '\n') - - heights[i] = lipgloss.Height(content) - checkpoints[i] = len(buf) } - buf = append(buf, '\n') // Gap between each message group + // buf = append(buf, '\n') // Gap between each message group } return string(buf) |
