Skip to content

The agent that grows with you

feat(desktop): page-scroll conversations with PageUp and PageDown

Tyler Lyon2d047b6bf968
diff --git a/apps/desktop/src/app/hooks/use-keybinds.ts b/apps/desktop/src/app/hooks/use-keybinds.ts
index 86049193ab4..175a25641a8 100644
--- a/apps/desktop/src/app/hooks/use-keybinds.ts
+++ b/apps/desktop/src/app/hooks/use-keybinds.ts
@@ -53,7 +53,7 @@ import { toggleProfileRailVisible } from '@/store/profile-rail-prefs'
import { openFolderAsProject } from '@/store/projects'
import { toggleReview } from '@/store/review'
import { $selectedStoredSessionId, setModelPickerOpen } from '@/store/session'
-import { reopenLastClosedTile } from '@/store/session-states'
+import { $focusedStoredSessionId, reopenLastClosedTile } from '@/store/session-states'
import {
$switcherOpen,
closeSwitcher,
@@ -66,6 +66,7 @@ import {
switcherJustClosed
} from '@/store/session-switcher'
import { toggleStatusbarVisible } from '@/store/statusbar-prefs'
+import { requestThreadPageScroll } from '@/store/thread-scroll'
import { openNewWindow } from '@/store/windows'
import { useTheme } from '@/themes/context'
@@ -241,6 +242,8 @@ export function useKeybinds(deps: KeybindRuntimeDeps): void {
'session.focusSearch': requestSessionSearchFocus,
'session.togglePin': deps.toggleSelectedPin,
'session.archive': deps.archiveSelectedSession,
+ 'conversation.scrollPageUp': () => requestThreadPageScroll(-1, $focusedStoredSessionId.get()),
+ 'conversation.scrollPageDown': () => requestThreadPageScroll(1, $focusedStoredSessionId.get()),
// openWorktreeDialog resolves the target. There is no test for a repo
// here, so the key works from a detached session that sits inside a
// project, and not only from a session with a repo. When no repo is in
diff --git a/apps/desktop/src/components/assistant-ui/thread/list-session-scroll.test.tsx b/apps/desktop/src/components/assistant-ui/thread/list-session-scroll.test.tsx
index 065ff46d276..15eb4611c32 100644
--- a/apps/desktop/src/components/assistant-ui/thread/list-session-scroll.test.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/list-session-scroll.test.tsx
@@ -4,10 +4,12 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
import { PaneLifecycleContext, PaneVisibleContext } from '@/components/pane-shell/pane-visibility'
import { rescopeConnectionScopedStores } from '@/lib/connection-scoped'
+import { keybindAction } from '@/lib/keybinds/actions'
import { setActiveProfile } from '@/store/profile'
import {
getThreadScrollPosition,
requestScrollToBottom,
+ requestThreadPageScroll,
saveThreadScrollPosition,
threadScrollStorageKey
} from '@/store/thread-scroll'
@@ -373,6 +375,36 @@ describe('list session-scroll restore', () => {
}
})
+ it('pages the requested conversation by exactly one viewport in either direction', async () => {
+ expect(keybindAction('conversation.scrollPageUp')?.defaults).toEqual(['pageup'])
+ expect(keybindAction('conversation.scrollPageDown')?.defaults).toEqual(['pagedown'])
+
+ const { container } = render(<ScrollHarness messages={sessionMessages('a')} sessionKey="a" />)
+ const vp = viewportEl(container)
+
+ await settleScroll()
+ expect(vp.scrollTop).toBe(SCROLL_H - CLIENT_H)
+
+ act(() => requestThreadPageScroll(1, 'a'))
+ expect(vp.scrollTop).toBe(SCROLL_H - CLIENT_H)
+ expect(vp.dataset.following).toBe('true')
+
+ act(() => requestThreadPageScroll(-1, 'other'))
+ expect(vp.scrollTop).toBe(SCROLL_H - CLIENT_H)
+
+ act(() => requestThreadPageScroll(-1, 'a'))
+ expect(vp.scrollTop).toBe(SCROLL_H - CLIENT_H * 2)
+ act(() => vp.dispatchEvent(new Event('scroll')))
+ await settleScroll()
+ expect(vp.dataset.following).toBe('false')
+
+ act(() => requestThreadPageScroll(1, 'a'))
+ expect(vp.scrollTop).toBe(SCROLL_H - CLIENT_H)
+ act(() => vp.dispatchEvent(new Event('scroll')))
+ await settleScroll()
+ expect(vp.dataset.following).toBe('true')
+ })
+
it('restores a reading offset on return after switching away', async () => {
saveThreadScrollPosition('a', { fromBottom: 800, kind: 'offset' })
diff --git a/apps/desktop/src/components/assistant-ui/thread/list.tsx b/apps/desktop/src/components/assistant-ui/thread/list.tsx
index 81620f62380..903bf29fd0f 100644
--- a/apps/desktop/src/components/assistant-ui/thread/list.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/list.tsx
@@ -28,6 +28,7 @@ import {
onScrollToBottomRequest,
onThreadEditClose,
onThreadEditOpen,
+ onThreadPageScrollRequest,
planThreadScrollRestore,
publishThreadAtBottom,
readThreadScrollResizeMetrics,
@@ -1325,6 +1326,52 @@ const ThreadMessageListInner: FC<ThreadMessageListProps> = ({
}
})
+ // Page the focused transcript explicitly. Browser-default PageUp/PageDown
+ // targets whichever ancestor happens to own focus, which is unreliable in
+ // the nested desktop layout. Keep the movement here with the thread's sole
+ // scroll owner, and key the request so split/kept-alive threads stay put.
+ useEffect(
+ () =>
+ onThreadPageScrollRequest(direction => {
+ const el = scrollRef.current
+
+ if (!el) {
+ return
+ }
+
+ // A no-op PageDown at the bottom must not escape sticky follow: the
+ // browser will clamp the write and emit no scroll event to re-lock it.
+ if (direction > 0 && threadScrollStateFromMetrics(el).kind === 'bottom') {
+ return
+ }
+
+ cancelRestoreRef.current?.()
+ stopScroll()
+
+ // At the clamped top there will be no native scroll event to trigger
+ // the existing automatic "Show earlier" path. Treat PageUp there like
+ // an upward wheel notch before moving the viewport.
+ if (
+ direction < 0 &&
+ shouldAutoShowEarlier({
+ action: resolveShowEarlierAction(hiddenCount, olderAvailable),
+ isAtBottom,
+ loadSettled: loadSettledRef.current,
+ restorePending: restoreFromBottomRef.current != null,
+ scrollTop: el.scrollTop,
+ wheelDeltaY: direction
+ })
+ ) {
+ showEarlier()
+
+ return
+ }
+
+ el.scrollTop += direction * el.clientHeight
+ }, sessionKey ?? null),
+ [hiddenCount, isAtBottom, olderAvailable, scrollRef, sessionKey, showEarlier, stopScroll]
+ )
+
// Scroll/wheel at the top edge pages older turns through the same showEarlier
// path as the button. Wheel is required because browsers emit no `scroll`
// once scrollTop is already 0 — exactly where the reader who wants more is.
diff --git a/apps/desktop/src/i18n/ar.ts b/apps/desktop/src/i18n/ar.ts
index 637962341c6..5ca0540d196 100644
--- a/apps/desktop/src/i18n/ar.ts
+++ b/apps/desktop/src/i18n/ar.ts
@@ -374,6 +374,8 @@ export const ar = defineLocale({
'session.slot.9': 'الانتقال إلى الجلسة الأخيرة 9',
'session.focusSearch': 'البحث في الجلسات',
'session.togglePin': 'تثبيت / إلغاء تثبيت الجلسة الحالية',
+ 'conversation.scrollPageUp': 'تمرير المحادثة صفحة إلى الأعلى',
+ 'conversation.scrollPageDown': 'تمرير المحادثة صفحة إلى الأسفل',
'workspace.newWorktree': 'worktree جديد',
'workspace.openFolder': 'فتح مجلد كمشروع',
'composer.focus': 'التركيز على المحرّر',
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index 5a94cc21209..9915fe36024 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -729,6 +729,8 @@ export const en: Translations = {
'session.focusSearch': 'Search sessions',
'session.togglePin': 'Pin / unpin current session',
'session.archive': 'Archive current session',
+ 'conversation.scrollPageUp': 'Scroll conversation up one page',
+ 'conversation.scrollPageDown': 'Scroll conversation down one page',
'workspace.newWorktree': 'New worktree',
'workspace.openFolder': 'Open folder as project',
'composer.focus': 'Focus composer',
diff --git a/apps/desktop/src/i18n/ru.ts b/apps/desktop/src/i18n/ru.ts
index 20bab74a8d5..e4aa6913cb3 100644
--- a/apps/desktop/src/i18n/ru.ts
+++ b/apps/desktop/src/i18n/ru.ts
@@ -390,6 +390,8 @@ export const ru = defineLocale({
'session.focusSearch': 'Поиск по сеансам',
'session.togglePin': 'Закрепить / открепить текущий сеанс',
'session.archive': 'В архив текущий сеанс',
+ 'conversation.scrollPageUp': 'Прокрутить диалог на страницу вверх',
+ 'conversation.scrollPageDown': 'Прокрутить диалог на страницу вниз',
'workspace.newWorktree': 'Новый worktree',
'workspace.openFolder': 'Открыть папку как проект',
'composer.focus': 'Сфокусировать композер',
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index 4485d53ab98..9a858f94818 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -443,6 +443,8 @@ export const zh = defineLocale({
'session.focusSearch': '搜索会话',
'session.togglePin': '固定/取消固定当前会话',
'session.archive': '归档当前会话',
+ 'conversation.scrollPageUp': '向上翻动一页会话',
+ 'conversation.scrollPageDown': '向下翻动一页会话',
'workspace.newWorktree': '新建工作树',
'workspace.openFolder': '打开文件夹为项目',
'composer.focus': '聚焦输入框',
diff --git a/apps/desktop/src/lib/keybinds/actions.ts b/apps/desktop/src/lib/keybinds/actions.ts
index e476cbad947..cbe2344401a 100644
--- a/apps/desktop/src/lib/keybinds/actions.ts
+++ b/apps/desktop/src/lib/keybinds/actions.ts
@@ -93,6 +93,8 @@ export const KEYBIND_ACTIONS: readonly KeybindActionMeta[] = [
...SESSION_SLOT_ACTIONS,
{ id: 'session.focusSearch', category: 'session', defaults: ['mod+shift+f'] },
{ id: 'session.togglePin', category: 'session', defaults: [] },
+ { id: 'conversation.scrollPageUp', category: 'session', defaults: ['pageup'] },
+ { id: 'conversation.scrollPageDown', category: 'session', defaults: ['pagedown'] },
// Archive the active session. Ships unbound (like `session.togglePin`) so an
// irreversible-feeling, mouse-only action doesn't silently claim a chord for
// every user — surfaced in the panel for opt-in binding (the issue suggests
diff --git a/apps/desktop/src/store/thread-scroll.ts b/apps/desktop/src/store/thread-scroll.ts
index 0b84cd1787d..a619258acae 100644
--- a/apps/desktop/src/store/thread-scroll.ts
+++ b/apps/desktop/src/store/thread-scroll.ts
@@ -108,6 +108,35 @@ export const requestScrollToBottom = (sessionId: string | null = null) => {
handlers.get(sessionId)?.forEach(handler => handler())
}
+export type ThreadPageDirection = -1 | 1
+
+// Bare PageUp/PageDown are global keybinds, while the scroll owner lives in
+// the focused thread. Route the intent by stable session key so kept-alive and
+// split transcripts cannot page together.
+const pageHandlers = new Map<string | null, Set<(direction: ThreadPageDirection) => void>>()
+
+export const onThreadPageScrollRequest = (
+ handler: (direction: ThreadPageDirection) => void,
+ sessionKey: string | null = null
+) => {
+ const scoped = pageHandlers.get(sessionKey) ?? new Set<(direction: ThreadPageDirection) => void>()
+
+ scoped.add(handler)
+ pageHandlers.set(sessionKey, scoped)
+
+ return () => {
+ scoped.delete(handler)
+
+ if (scoped.size === 0) {
+ pageHandlers.delete(sessionKey)
+ }
+ }
+}
+
+export const requestThreadPageScroll = (direction: ThreadPageDirection, sessionKey: string | null = null) => {
+ pageHandlers.get(sessionKey)?.forEach(handler => handler(direction))
+}
+
// Inline edit grows a sticky human bubble. Fire on pointerdown so the viewport
// escapes stick-to-bottom before focus/layout; close clears the edit flag when
// the inline composer unmounts.