feat(tui): add setting to keep scroll position on send (#61460)

A new session.submit_scroll setting controls this jump. With "keep", the transcript stays where it is when you send a prompt, and the "Jump to latest" link stays visible. If you are already at the bottom, new messages still follow as before. The default, "bottom", keeps the current behavior. The setting is in the settings dialog as "Scroll on send" and in the session configuration docs.
This commit is contained in:
Simon Klee
2026-11-03 19:27:20 +01:00
committed by GitHub
Unverified
parent ace4bbdf1e
commit bea50be4b6
5 changed files with 101 additions and 1 deletions
@@ -75,6 +75,16 @@ export const settings: Setting[] = [
labels: ["off", "on"],
keywords: ["scroll bar"],
},
{
title: "Scroll on send",
category: "Session",
path: ["session", "submit_scroll"],
description: "Whether sending a prompt jumps to the latest message",
default: "bottom",
values: ["bottom", "keep"],
labels: ["jump to latest", "keep position"],
keywords: ["submit", "scroll position", "jump to latest", "follow"],
},
{
title: "Thinking",
category: "Session",
+3
View File
@@ -155,6 +155,9 @@ export const Info = Schema.Struct({
description: "Session sidebar visibility; 'auto' shows it when space permits",
}),
scrollbar: Schema.optional(Schema.Boolean).annotate({ description: "Show the session transcript scrollbar" }),
submit_scroll: Schema.optional(Schema.Literals(["bottom", "keep"])).annotate({
description: "Jump to the latest message when sending a prompt, or keep the current transcript position",
}),
thinking: Schema.optional(Schema.Literals(["show", "hide"])).annotate({
description: "Show or hide model reasoning by default",
}),
+1 -1
View File
@@ -1648,7 +1648,7 @@ export function Session(props: {
ref={bind}
muted={props.promptMuted}
onSubmit={() => {
toBottom()
if (config.session?.submit_scroll !== "keep") toBottom()
}}
onEmptySubmit={async () => {
const next = queuedPrompts()[0]
@@ -0,0 +1,85 @@
import { expect, test } from "bun:test"
import { type Renderable, ScrollBoxRenderable } from "@opentui/core"
import { createAppFixture } from "./fixture/app"
import { directory, json } from "./fixture/tui-client"
test.each([
{ setting: undefined, kept: false },
{ setting: "keep" as const, kept: true },
])("sending a prompt while scrolled up with session.submit_scroll $setting", async ({ setting, kept }) => {
const sessionID = "ses_submit_scroll"
const location = { directory, project: { id: "project", directory, canonical: directory } }
const messages = Array.from({ length: 40 }, (_, index) => ({
id: `message-${index}`,
type: "user",
text: `History message ${String(index).padStart(4, "0")}`,
time: { created: index },
}))
const prompted = Promise.withResolvers<string>()
await using app = await createAppFixture({
width: 100,
height: 30,
args: { sessionID },
config: { animations: false, tabs: { mode: "off" }, session: { submit_scroll: setting } },
fetch: async (url, request) => {
if (url.pathname === `/api/session/${sessionID}`)
return json({
data: {
id: sessionID,
projectID: "project",
title: "Submit scroll fixture",
agent: "build",
model: { providerID: "demo", id: "model" },
location: { directory },
cost: 0,
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
time: { created: 0, updated: 0 },
},
})
if (url.pathname === `/api/session/${sessionID}/message`) return json({ data: messages.toReversed(), cursor: {} })
if (url.pathname === `/api/session/${sessionID}/inbox`) return json({ data: [] })
if (url.pathname === "/api/agent")
return json({ location, data: [{ id: "build", mode: "primary", hidden: false, permissions: [] }] })
if (url.pathname === "/api/provider") return json({ location, data: [{ id: "demo", name: "Demo" }] })
if (url.pathname === "/api/model")
return json({ location, data: [{ id: "model", providerID: "demo", name: "Demo Model", variants: [] }] })
if (url.pathname === `/api/session/${sessionID}/prompt`) {
const body = await request.json()
prompted.resolve(body.id)
return json({
data: { id: body.id, sessionID, type: "user", time: { created: 100 }, payload: { text: body.text } },
})
}
return undefined
},
})
await app.ready
await app.waitForFrame((frame) => frame.includes("History message 0039") && frame.includes("Demo Model"))
const find = (root: Renderable): ScrollBoxRenderable | undefined =>
root instanceof ScrollBoxRenderable && root.getRenderable("message-39")
? root
: root.getChildren().map(find).find(Boolean)
const scroll = find(app.renderer.root)
if (!scroll) throw new Error("Session scrollbox not found")
for (let tick = 0; tick < 3; tick++) await app.mockMouse.scroll(scroll.viewport.x + 2, scroll.viewport.y + 2, "up")
await app.waitForFrame((frame) => frame.includes("Jump to latest"))
await app.waitForVisualIdle({ quietFrames: 3 })
const before = scroll.scrollTop
expect(before).toBeLessThan(scroll.scrollHeight - scroll.viewport.height)
await app.mockInput.typeText("Follow-up prompt")
app.mockInput.pressEnter()
const id = await prompted.promise
await app.waitFor(() => !!scroll.getRenderable(id))
// Outlasts the delayed jump to the bottom, which starts when the prompt is sent.
await app.waitForVisualIdle({ quietFrames: 3 })
if (kept) {
expect(scroll.scrollTop).toBe(before)
expect(app.captureCharFrame()).toContain("Jump to latest")
return
}
expect(scroll.scrollTop).toBe(Math.max(0, scroll.scrollHeight - scroll.viewport.height))
expect(app.captureCharFrame()).toContain("Follow-up prompt")
expect(app.captureCharFrame()).not.toContain("Jump to latest")
})
@@ -119,6 +119,7 @@ Configure how full-screen TUI sessions are presented and where new sessions star
"session": {
"sidebar": "auto",
"scrollbar": false,
"submit_scroll": "bottom",
"thinking": "hide",
"grouping": "auto",
"image_preview": false,
@@ -136,6 +137,7 @@ Configure how full-screen TUI sessions are presented and where new sessions star
| ----------------------- | --------------------------- | ---------------------------------------------------------------------------- |
| `session.sidebar` | `auto` or `hide` | Shows the sidebar when space permits or always hides it. |
| `session.scrollbar` | boolean | Shows the transcript scrollbar. |
| `session.submit_scroll` | `bottom` or `keep` | Jumps to the latest message when you send a prompt, or keeps your position. |
| `session.thinking` | `show` or `hide` | Shows or hides model reasoning by default. |
| `session.grouping` | `auto` or `none` | Groups related transcript items or renders each item separately. |
| `session.image_preview` | boolean | Shows user attachment and tool-result images in the transcript. |