Skip to content

Commit 91ed101

Browse files
authored
feat(desktop): implement auto-scroll for active command in slash popover (#6797)
1 parent fb60f9c commit 91ed101

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/app/src/components/prompt-input.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
106106
let editorRef!: HTMLDivElement
107107
let fileInputRef!: HTMLInputElement
108108
let scrollRef!: HTMLDivElement
109+
let slashPopoverRef!: HTMLDivElement
109110

110111
const scrollCursorIntoView = () => {
111112
const container = scrollRef
@@ -502,6 +503,17 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
502503
),
503504
)
504505

506+
// Auto-scroll active command into view when navigating with keyboard
507+
createEffect(() => {
508+
const activeId = slashActive()
509+
if (!activeId || !slashPopoverRef) return
510+
511+
requestAnimationFrame(() => {
512+
const element = slashPopoverRef.querySelector(`[data-slash-id="${activeId}"]`)
513+
element?.scrollIntoView({ block: "nearest", behavior: "smooth" })
514+
})
515+
})
516+
505517
createEffect(
506518
on(
507519
() => prompt.current(),
@@ -1258,6 +1270,9 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
12581270
<div class="relative size-full _max-h-[320px] flex flex-col gap-3">
12591271
<Show when={store.popover}>
12601272
<div
1273+
ref={(el) => {
1274+
if (store.popover === "slash") slashPopoverRef = el
1275+
}}
12611276
class="absolute inset-x-0 -top-3 -translate-y-full origin-bottom-left max-h-80 min-h-10
12621277
overflow-auto no-scrollbar flex flex-col p-2 rounded-md
12631278
border border-border-base bg-surface-raised-stronger-non-alpha shadow-md"
@@ -1316,6 +1331,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
13161331
<For each={slashFlat()}>
13171332
{(cmd) => (
13181333
<button
1334+
data-slash-id={cmd.id}
13191335
classList={{
13201336
"w-full flex items-center justify-between gap-4 rounded-md px-2 py-1": true,
13211337
"bg-surface-raised-base-hover": slashActive() === cmd.id,

0 commit comments

Comments
 (0)