Skip to content

Commit d924074

Browse files
authored
[CAP-7450] Follow-up fix to viewport offset bug on first scroll (#244)
Fixes a visual bug in #243, which introduced paginated infinite scroll for CLI logs, in which the viewport shifts too much when a user first triggers an additional logs fetch. (The only real change here is adding a SetContent call before SetYOffset.)
1 parent 3c74b02 commit d924074

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pkg/tui/logs.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ func (m *LogModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
118118
cmds []tea.Cmd
119119
)
120120

121-
// Check if user is trying to scroll up while at top (before viewport
122-
// update); this is always the case after initial load
121+
// Check if user is trying to scroll up while at top before the viewport has
122+
// updated; this is always the case when scrolling up after the initial load
123123
wasAtTop := m.viewport.AtTop()
124124
userTriedToScrollUp := false
125125

@@ -178,9 +178,12 @@ func (m *LogModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
178178
if m.direction == lclient.Backward {
179179
// Backward direction: paginated scroll prepends older logs
180180
m.content = append(newContent, m.content...)
181-
// Adjust viewport to maintain user's scroll position
182-
newYOffset := m.viewport.YOffset + len(newContent)
183-
m.viewport.SetYOffset(newYOffset)
181+
// Set content first so the viewport knows the new valid
182+
// range, then adjust the viewport to maintain the current
183+
// scroll position. It's fine for SetContent to be called
184+
// again outside of this block.
185+
m.viewport.SetContent(strings.Join(m.content, "\n"))
186+
m.viewport.SetYOffset(m.viewport.YOffset + len(newContent))
184187
} else {
185188
// Forward direction: paginated scroll appends newer logs
186189
m.content = append(m.content, newContent...)
@@ -189,7 +192,6 @@ func (m *LogModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
189192
} else {
190193
// Initial load
191194
m.content = formatLogs(msg.Data.Logs.Logs)
192-
// Mark initial load as complete (but only after first viewport update)
193195
}
194196

195197
// Update pagination state

0 commit comments

Comments
 (0)