Skip to content

Commit 10d3622

Browse files
committed
fix(tui): disable sticky scroll when user scrolls up during LLM response
When a user scrolls up to read chat history while an LLM is still streaming, the view would snap back to the bottom on every token update due to stickyScroll=true always forcing scroll-to-bottom. This change tracks user scroll state via a userScrolledUp signal and makes stickyScroll reactive - only auto-scrolling when the user is at the bottom. User scroll commands (page up, line up, first message) set the flag to pause auto-scroll, while toBottom() and last message reset it to resume. Fixes anomalyco#4196
1 parent 41612b3 commit 10d3622

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

  • packages/opencode/src/cli/cmd/tui/routes/session

‎packages/opencode/src/cli/cmd/tui/routes/session/index.tsx‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export function Session() {
153153
const [diffWrapMode] = kv.signal<"word" | "none">("diff_wrap_mode", "word")
154154
const [animationsEnabled, setAnimationsEnabled] = kv.signal("animations_enabled", true)
155155
const [showGenericToolOutput, setShowGenericToolOutput] = kv.signal("generic_tool_output_visibility", false)
156+
const [userScrolledUp, setUserScrolledUp] = createSignal(false)
156157

157158
const wide = createMemo(() => dimensions().width > 120)
158159
const sidebarVisible = createMemo(() => {
@@ -178,6 +179,7 @@ export function Session() {
178179
.sync(route.sessionID)
179180
.then(() => {
180181
if (scroll) scroll.scrollBy(100_000)
182+
setUserScrolledUp(false)
181183
})
182184
.catch((e) => {
183185
console.error(e)
@@ -303,6 +305,7 @@ export function Session() {
303305
setTimeout(() => {
304306
if (!scroll || scroll.isDestroyed) return
305307
scroll.scrollTo(scroll.scrollHeight)
308+
setUserScrolledUp(false)
306309
}, 50)
307310
}
308311

@@ -645,6 +648,7 @@ export function Session() {
645648
hidden: true,
646649
onSelect: (dialog) => {
647650
scroll.scrollBy(-scroll.height / 2)
651+
setUserScrolledUp(true)
648652
dialog.clear()
649653
},
650654
},
@@ -667,6 +671,7 @@ export function Session() {
667671
disabled: true,
668672
onSelect: (dialog) => {
669673
scroll.scrollBy(-1)
674+
setUserScrolledUp(true)
670675
dialog.clear()
671676
},
672677
},
@@ -689,6 +694,7 @@ export function Session() {
689694
hidden: true,
690695
onSelect: (dialog) => {
691696
scroll.scrollBy(-scroll.height / 4)
697+
setUserScrolledUp(true)
692698
dialog.clear()
693699
},
694700
},
@@ -711,6 +717,7 @@ export function Session() {
711717
hidden: true,
712718
onSelect: (dialog) => {
713719
scroll.scrollTo(0)
720+
setUserScrolledUp(true)
714721
dialog.clear()
715722
},
716723
},
@@ -722,6 +729,7 @@ export function Session() {
722729
hidden: true,
723730
onSelect: (dialog) => {
724731
scroll.scrollTo(scroll.scrollHeight)
732+
setUserScrolledUp(false)
725733
dialog.clear()
726734
},
727735
},
@@ -1047,7 +1055,7 @@ export function Session() {
10471055
foregroundColor: theme.border,
10481056
},
10491057
}}
1050-
stickyScroll={true}
1058+
stickyScroll={!userScrolledUp()}
10511059
stickyStart="bottom"
10521060
flexGrow={1}
10531061
scrollAcceleration={scrollAcceleration()}

0 commit comments

Comments
 (0)