Skip to content

Commit 7570fb9

Browse files
neriousy吕绍波
authored andcommitted
fix(app): keyboard navigation previous/next message (anomalyco#15047)
1 parent 55d7563 commit 7570fb9

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

packages/app/src/pages/session.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,13 @@ export default function Page() {
254254
const msgs = visibleUserMessages()
255255
if (msgs.length === 0) return
256256

257-
const current = activeMessage()
258-
const currentIndex = current ? msgs.findIndex((m) => m.id === current.id) : -1
259-
const targetIndex = currentIndex === -1 ? (offset > 0 ? 0 : msgs.length - 1) : currentIndex + offset
260-
if (targetIndex < 0 || targetIndex >= msgs.length) return
257+
const current = store.messageId
258+
const base = current ? msgs.findIndex((m) => m.id === current) : msgs.length
259+
const currentIndex = base === -1 ? msgs.length : base
260+
const targetIndex = currentIndex + offset
261+
if (targetIndex < 0 || targetIndex > msgs.length) return
261262

262-
if (targetIndex === msgs.length - 1) {
263+
if (targetIndex === msgs.length) {
263264
resumeScroll()
264265
return
265266
}

packages/app/src/pages/session/message-timeline.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ export function MessageTimeline(props: {
376376
>
377377
<Show when={showHeader()}>
378378
<div
379+
data-session-title
379380
classList={{
380381
"sticky top-0 z-30 bg-[linear-gradient(to_bottom,var(--background-stronger)_48px,transparent)]": true,
381382
"w-full": true,

packages/app/src/pages/session/use-session-hash-scroll.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ export const useSessionHashScroll = (input: {
4545

4646
const a = el.getBoundingClientRect()
4747
const b = root.getBoundingClientRect()
48-
const top = a.top - b.top + root.scrollTop
48+
const sticky = root.querySelector("[data-session-title]")
49+
const inset = sticky instanceof HTMLElement ? sticky.offsetHeight : 0
50+
const top = Math.max(0, a.top - b.top + root.scrollTop - inset)
4951
root.scrollTo({ top, behavior })
5052
return true
5153
}

0 commit comments

Comments
 (0)