mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 03:24:54 +00:00
feat(ui): keep branch search results on screen while a query is pending (#57531)
This commit is contained in:
parent
fe594884c6
commit
0e8f953201
13 changed files with 416 additions and 255 deletions
|
|
@ -57,7 +57,7 @@ test("titlebar search lists recent sessions and opens the typed match", async ({
|
|||
await openPaletteWorkspace(page, true)
|
||||
await page.getByRole("banner").getByRole("button", { name: "Search sessions", exact: true }).click()
|
||||
const dialog = page.getByRole("dialog")
|
||||
const input = dialog.getByRole("textbox")
|
||||
const input = dialog.getByRole("combobox")
|
||||
await expect(input).toBeFocused()
|
||||
await expect(input).toHaveAttribute("placeholder", "Search sessions")
|
||||
await expect(dialog.getByText("Recent sessions", { exact: true })).toBeVisible()
|
||||
|
|
@ -78,7 +78,7 @@ test("reopens from its shortcut as soon as it closes", async ({ page }) => {
|
|||
await expect(dialog).toHaveCount(0)
|
||||
// A closed dialog stops blocking shortcuts when it leaves the screen, not when it is disposed afterwards.
|
||||
await page.keyboard.press("ControlOrMeta+Shift+P")
|
||||
await expect(dialog.getByRole("textbox")).toBeFocused()
|
||||
await expect(dialog.getByRole("combobox")).toBeFocused()
|
||||
})
|
||||
|
||||
test("appends search results without resetting the selected command", async ({ page }) => {
|
||||
|
|
@ -224,11 +224,11 @@ test("navigation replaces commands without retaining disposed owners", async ({
|
|||
await expect(editor).toBeFocused()
|
||||
await page.keyboard.press("ControlOrMeta+Shift+P")
|
||||
const dialog = page.getByRole("dialog")
|
||||
await expect(dialog.getByRole("textbox")).toBeFocused()
|
||||
await expect(dialog.getByRole("textbox")).toHaveAttribute("placeholder", "Search files, commands, and sessions")
|
||||
await dialog.getByRole("textbox").fill("copy session")
|
||||
await expect(dialog.getByRole("combobox")).toBeFocused()
|
||||
await expect(dialog.getByRole("combobox")).toHaveAttribute("placeholder", "Search files, commands, and sessions")
|
||||
await dialog.getByRole("combobox").fill("copy session")
|
||||
await expect(dialog.getByRole("option", { name: "Copy Session ID", exact: true })).toHaveCount(0)
|
||||
await dialog.getByRole("textbox").press("Escape")
|
||||
await dialog.getByRole("combobox").press("Escape")
|
||||
await expect(dialog).toHaveCount(0)
|
||||
const tabs = page.locator("[data-titlebar-tab-link]")
|
||||
await tabs.filter({ hasText: paletteSession.title }).click()
|
||||
|
|
@ -255,8 +255,8 @@ test("navigation replaces commands without retaining disposed owners", async ({
|
|||
await tabs.filter({ hasText: paletteSession.title }).click()
|
||||
await expect(page.getByRole("heading", { name: paletteSession.title, exact: true })).toBeVisible()
|
||||
await page.keyboard.press("ControlOrMeta+Shift+P")
|
||||
await expect(dialog.getByRole("textbox")).toBeFocused()
|
||||
await dialog.getByRole("textbox").fill("copy session")
|
||||
await expect(dialog.getByRole("combobox")).toBeFocused()
|
||||
await dialog.getByRole("combobox").fill("copy session")
|
||||
await expect(dialog.getByRole("option", { name: "Copy Session ID", exact: true })).toHaveAttribute(
|
||||
"aria-selected",
|
||||
"true",
|
||||
|
|
@ -271,7 +271,7 @@ test("keeps matching session and file results steady across keystrokes while sea
|
|||
const mac = await page.evaluate(() => /(Mac|iPod|iPhone|iPad)/.test(navigator.platform))
|
||||
await page.keyboard.press(mac ? "Meta+Shift+P" : "Control+Shift+P")
|
||||
const dialog = page.getByRole("dialog")
|
||||
const input = dialog.getByRole("textbox")
|
||||
const input = dialog.getByRole("combobox")
|
||||
await expect(input).toBeFocused()
|
||||
const sessionOption = dialog.getByRole("option", { name: /Palette fixture session/ })
|
||||
const matchingFile = dialog.getByRole("option", { name: "packages/desktop/ palette.ts", exact: true })
|
||||
|
|
|
|||
|
|
@ -307,7 +307,7 @@ test("a narrow-screen palette pick keeps the view, and the side region shows the
|
|||
await expect(terminal.locator("textarea")).toBeEditable()
|
||||
await page.keyboard.press("ControlOrMeta+p")
|
||||
const dialog = page.getByRole("dialog")
|
||||
await dialog.getByRole("textbox").fill("README")
|
||||
await dialog.getByRole("combobox").fill("README")
|
||||
await dialog.getByRole("option", { name: "/ README.md", exact: true }).click()
|
||||
await expect(dialog).toHaveCount(0)
|
||||
await expect(tabs.getByRole("tab", { selected: true })).toHaveText("More...")
|
||||
|
|
|
|||
|
|
@ -78,15 +78,16 @@ test("the combined location picker shows checkout branches and chooses the base
|
|||
await expect(base).toBeVisible()
|
||||
expect(searches).toEqual([])
|
||||
await base.click()
|
||||
const search = page.getByRole("textbox", { name: "Search branches", exact: true })
|
||||
const search = page.getByRole("combobox", { name: "Search branches", exact: true })
|
||||
await expect(search).toBeFocused()
|
||||
await expect(page.getByText("Loading", { exact: true })).toBeVisible()
|
||||
await expect(search).toHaveAttribute("aria-busy", "true")
|
||||
await expect(newSessionLocation(page)).toBeVisible()
|
||||
listed.resolve(["timeline-quotes", "release/base", "origin/dev"])
|
||||
await expect(page.getByRole("menuitemradio", { name: "release/base", exact: true })).toBeVisible()
|
||||
await expect(page.getByRole("option", { name: "release/base", exact: true })).toBeVisible()
|
||||
await search.fill("release")
|
||||
await expect(page.getByRole("menuitemradio")).toHaveText(["release/base"])
|
||||
await page.getByRole("menuitemradio", { name: "release/base", exact: true }).click()
|
||||
await expect(search).toHaveAttribute("aria-busy", "false")
|
||||
await expect(page.getByRole("option")).toHaveText(["release/base"])
|
||||
await page.getByRole("option", { name: "release/base", exact: true }).click()
|
||||
const selected = screen.getByRole("button", { name: "from release/base", exact: true })
|
||||
await expect(selected).toBeVisible()
|
||||
await expect(view.editor).toBeFocused()
|
||||
|
|
@ -107,7 +108,7 @@ test("the combined location picker shows checkout branches and chooses the base
|
|||
|
||||
const select = async (name: RegExp) => {
|
||||
await newSessionLocation(page).click()
|
||||
await page.getByRole("textbox", { name: "Search projects", exact: true }).press("ArrowRight")
|
||||
await page.getByRole("combobox", { name: "Search projects", exact: true }).press("ArrowRight")
|
||||
await page.getByRole("option", { name }).click()
|
||||
await expect(view.editor).toBeFocused()
|
||||
}
|
||||
|
|
@ -122,7 +123,7 @@ test("the combined location picker shows checkout branches and chooses the base
|
|||
await expect(base).toBeVisible()
|
||||
await base.click()
|
||||
await expect(search).toBeFocused()
|
||||
await page.getByRole("menuitemradio", { name: "origin/dev", exact: true }).click()
|
||||
await page.getByRole("option", { name: "origin/dev", exact: true }).click()
|
||||
await expect(screen.getByRole("button", { name: "from origin/dev", exact: true })).toBeVisible()
|
||||
await view.editor.fill("Use the selected base")
|
||||
await submit(page).click()
|
||||
|
|
@ -135,6 +136,48 @@ test("the combined location picker shows checkout branches and chooses the base
|
|||
.toEqual([expect.objectContaining({ body: expect.objectContaining({ text: "Use the selected base" }) })])
|
||||
})
|
||||
|
||||
test("branch search keeps results on screen while a query is pending", async ({ page }) => {
|
||||
const held = Promise.withResolvers<string[]>()
|
||||
|
||||
await openWorktreeDraft(page, {
|
||||
name: "BranchPending",
|
||||
vcs: () => ({ current: "dev", default: "dev" }),
|
||||
branches: (input) => (input.search ? held.promise : ["dev", "release/base", "release/next", "timeline-quotes"]),
|
||||
})
|
||||
|
||||
await page.getByRole("button", { name: "from dev", exact: true }).click()
|
||||
const search = page.getByRole("combobox", { name: "Search branches", exact: true })
|
||||
const options = page.getByRole("option")
|
||||
await expect(options).toHaveCount(4)
|
||||
// Record any moment the list renders without rows, however brief.
|
||||
await page.getByRole("listbox").evaluate((list) => {
|
||||
const observer = new MutationObserver(() => {
|
||||
if (!list.querySelector('[role="option"]')) list.setAttribute("data-emptied", "")
|
||||
})
|
||||
observer.observe(list, { childList: true, subtree: true })
|
||||
})
|
||||
|
||||
const next = page.getByRole("option", { name: "release/next", exact: true })
|
||||
await search.press("ArrowDown")
|
||||
await search.press("ArrowDown")
|
||||
await expect(next).toHaveAttribute("aria-selected", "true")
|
||||
await search.pressSequentially("release")
|
||||
await expect(search).toHaveAttribute("aria-busy", "true")
|
||||
await expect(options).toHaveText(["release/base", "release/next"])
|
||||
await expect(next).toHaveAttribute("aria-selected", "true")
|
||||
await search.press("ControlOrMeta+a")
|
||||
await search.press("Backspace")
|
||||
await expect(options).toHaveCount(4)
|
||||
await search.pressSequentially("quotes")
|
||||
await expect(options).toHaveText(["timeline-quotes"])
|
||||
await search.pressSequentially("-missing")
|
||||
await expect(options).toHaveText(["timeline-quotes"])
|
||||
await expect(page.getByRole("listbox")).not.toHaveAttribute("data-emptied")
|
||||
held.resolve([])
|
||||
await expect(page.getByText("No results found", { exact: true })).toBeVisible()
|
||||
await expect(search).toHaveAttribute("aria-busy", "false")
|
||||
})
|
||||
|
||||
test("the dark new session panel exposes no lighter background at its rounded corners", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 935, height: 522 })
|
||||
await openDraft(page, { name: "PanelCorner", seed: { theme: { id: "oc-2", scheme: "dark" } } })
|
||||
|
|
@ -538,7 +581,7 @@ test("the location dialog lists every ready server's projects in one list and ta
|
|||
|
||||
await newSessionLocation(page).click()
|
||||
const dialog = page.getByRole("dialog")
|
||||
const search = dialog.getByRole("textbox")
|
||||
const search = dialog.getByRole("combobox")
|
||||
await expect(search).toBeFocused()
|
||||
const options = dialog.getByRole("option")
|
||||
const names = options.locator(".new-session-location-name")
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ test("keeps the side panel's tabs and selection when the session moves", async (
|
|||
await page.keyboard.press("ControlOrMeta+Shift+P")
|
||||
|
||||
const dialog = page.getByRole("dialog")
|
||||
const search = dialog.getByRole("textbox")
|
||||
const search = dialog.getByRole("combobox")
|
||||
await search.fill(name)
|
||||
await expect(dialog.getByRole("option", { name: `/ ${name}.md`, exact: true })).toHaveAttribute(
|
||||
"aria-selected",
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ test("focuses the terminal opened from the command palette", async ({ page }) =>
|
|||
await editor.click()
|
||||
await page.keyboard.press("ControlOrMeta+Shift+P")
|
||||
const palette = page.getByRole("dialog")
|
||||
const search = palette.getByRole("textbox")
|
||||
const search = palette.getByRole("combobox")
|
||||
await expect(search).toBeFocused()
|
||||
await search.fill("Toggle terminal")
|
||||
await expect(palette.getByRole("option", { name: /^Toggle terminal/ })).toHaveAttribute("aria-selected", "true")
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ export async function openCommandPalette(page: Page, home = false) {
|
|||
const mock = await openPaletteWorkspace(page, home)
|
||||
await page.keyboard.press("ControlOrMeta+Shift+P")
|
||||
const dialog = page.getByRole("dialog")
|
||||
const input = dialog.getByRole("textbox")
|
||||
const input = dialog.getByRole("combobox")
|
||||
await expect(input).toBeFocused()
|
||||
await expect(dialog.getByRole("option")).not.toHaveCount(0)
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import {
|
|||
} from "@opencode/ui/project-avatar"
|
||||
import { ScrollView } from "@opencode/ui/scroll-view"
|
||||
import { TextInput } from "@opencode/ui/text-input"
|
||||
import { createTypeahead } from "@opencode/ui/typeahead"
|
||||
import { getFilename } from "@opencode/util/path"
|
||||
import { createEffect, createMemo, createResource, For, type JSX, Match, onCleanup, Show, Switch } from "solid-js"
|
||||
import { createStore } from "solid-js/store"
|
||||
|
|
@ -70,7 +71,6 @@ function NewSessionLocationDialog(props: {
|
|||
/** Picking the server to add a project to. */
|
||||
picking?: boolean
|
||||
query: string
|
||||
active?: string
|
||||
/** The projects view to restore when stepping back out of a project or the server step. */
|
||||
back?: { query: string; active: string }
|
||||
}>({ query: "" })
|
||||
|
|
@ -177,8 +177,14 @@ function NewSessionLocationDialog(props: {
|
|||
|
||||
const choosesServer = () => props.project.servers().length > 1
|
||||
|
||||
// Every step opens on its first row; the user's choice wins until the results change.
|
||||
const activeEntry = createMemo(() => entries().find((entry) => entry.id === store.active) ?? entries()[0])
|
||||
// Every step opens on its first row; the user's choice holds while it stays in the results.
|
||||
const typeahead = createTypeahead<LocationEntry>({
|
||||
items: entries,
|
||||
key: (entry) => entry.id,
|
||||
onSelect: choose,
|
||||
})
|
||||
|
||||
const activeEntry = typeahead.activeItem
|
||||
|
||||
let resultsRef: HTMLDivElement | undefined
|
||||
let inputRef: HTMLInputElement | undefined
|
||||
|
|
@ -200,28 +206,19 @@ function NewSessionLocationDialog(props: {
|
|||
}
|
||||
|
||||
function drill(project: PromptProject) {
|
||||
setStore({
|
||||
drilled: project,
|
||||
query: "",
|
||||
active: undefined,
|
||||
back: { query: store.query, active: projectEntryID(project) },
|
||||
})
|
||||
setStore({ drilled: project, query: "", back: { query: store.query, active: projectEntryID(project) } })
|
||||
inputRef?.focus()
|
||||
}
|
||||
|
||||
function pick() {
|
||||
setStore({ picking: true, query: "", active: undefined, back: { query: store.query, active: "add" } })
|
||||
setStore({ picking: true, query: "", back: { query: store.query, active: "add" } })
|
||||
inputRef?.focus()
|
||||
}
|
||||
|
||||
function back() {
|
||||
setStore({
|
||||
drilled: undefined,
|
||||
picking: undefined,
|
||||
query: store.back?.query ?? "",
|
||||
active: store.back?.active,
|
||||
back: undefined,
|
||||
})
|
||||
const active = store.back?.active
|
||||
setStore({ drilled: undefined, picking: undefined, query: store.back?.query ?? "", back: undefined })
|
||||
typeahead.setActive(active)
|
||||
inputRef?.focus()
|
||||
}
|
||||
|
||||
|
|
@ -266,34 +263,12 @@ function NewSessionLocationDialog(props: {
|
|||
dialog.close()
|
||||
}
|
||||
|
||||
const move = (delta: -1 | 1) => {
|
||||
const list = entries()
|
||||
|
||||
if (list.length === 0) return
|
||||
const index = list.findIndex((entry) => entry.id === activeEntry()?.id)
|
||||
setStore("active", list[(index + delta + list.length) % list.length].id)
|
||||
}
|
||||
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
const target = event.currentTarget as HTMLInputElement
|
||||
const atEnd = target.selectionStart === target.value.length && target.selectionEnd === target.value.length
|
||||
const atStart = target.selectionStart === 0 && target.selectionEnd === 0
|
||||
const active = activeEntry()
|
||||
|
||||
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
||||
event.preventDefault()
|
||||
move(event.key === "ArrowDown" ? 1 : -1)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (event.key === "Enter" && !event.isComposing) {
|
||||
event.preventDefault()
|
||||
choose(active)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (event.key === "ArrowRight" && atEnd && active?.type === "project" && drillable(active.project)) {
|
||||
event.preventDefault()
|
||||
drill(active.project)
|
||||
|
|
@ -314,7 +289,11 @@ function NewSessionLocationDialog(props: {
|
|||
) {
|
||||
event.preventDefault()
|
||||
back()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
typeahead.onKeyDown(event)
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
@ -354,17 +333,22 @@ function NewSessionLocationDialog(props: {
|
|||
</Match>
|
||||
</Switch>
|
||||
}
|
||||
onInput={(event) => setStore({ query: event.currentTarget.value, active: undefined })}
|
||||
role="combobox"
|
||||
aria-expanded="true"
|
||||
aria-controls={typeahead.listID}
|
||||
aria-activedescendant={typeahead.activeID()}
|
||||
onInput={(event) => setStore("query", event.currentTarget.value)}
|
||||
onKeyDown={handleKeyDown}
|
||||
/>
|
||||
</div>
|
||||
<ScrollView class="command-palette-scroll" viewportRef={(el) => (resultsRef = el)}>
|
||||
<div class="command-palette-results" role="listbox">
|
||||
<div id={typeahead.listID} class="command-palette-results" role="listbox">
|
||||
<Show
|
||||
when={entries().length > 0}
|
||||
fallback={
|
||||
<div class="command-palette-state">
|
||||
{store.drilled && listed.loading ? language.t("common.loading") : language.t("palette.empty")}
|
||||
// The worktree list may still be loading; hold the row's height without flashing a label.
|
||||
<div class="command-palette-state" classList={{ invisible: !!store.drilled && listed.loading }}>
|
||||
{language.t("palette.empty")}
|
||||
</div>
|
||||
}
|
||||
>
|
||||
|
|
@ -374,6 +358,7 @@ function NewSessionLocationDialog(props: {
|
|||
{(entry) => (
|
||||
<button
|
||||
type="button"
|
||||
id={typeahead.optionID(entry)}
|
||||
class="command-palette-row"
|
||||
role="option"
|
||||
aria-selected={activeEntry()?.id === entry.id}
|
||||
|
|
@ -381,7 +366,7 @@ function NewSessionLocationDialog(props: {
|
|||
onMouseMove={(event) => {
|
||||
// Ignore hover from a static cursor when keyboard scrolling moves rows underneath it.
|
||||
if (event.movementX === 0 && event.movementY === 0) return
|
||||
setStore("active", entry.id)
|
||||
typeahead.setActive(entry.id)
|
||||
}}
|
||||
onMouseDown={(event) => event.preventDefault()}
|
||||
onClick={() => choose(entry)}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import { debounce } from "@solid-primitives/scheduled"
|
||||
import { createEffect, createMemo, createResource, onCleanup } from "solid-js"
|
||||
import { createStore } from "solid-js/store"
|
||||
import { useWorkspaceLocation } from "@/workspaces/location"
|
||||
|
|
@ -62,14 +61,9 @@ export function createNewSessionWorkspaceController(input: {
|
|||
const tabs = useTabs()
|
||||
|
||||
const [state, setState] = createStore({
|
||||
branchesOpen: false,
|
||||
search: "",
|
||||
existing: undefined as { projectID: string; directory: string } | undefined,
|
||||
})
|
||||
|
||||
const searchBranches = debounce((search: string) => setState("search", search.trim()), 100)
|
||||
onCleanup(searchBranches.clear)
|
||||
|
||||
const currentProject = createMemo(() => {
|
||||
const projectID = data.location.info({ directory: sdk().directory })?.project.id
|
||||
const current = projectID ? data.project.get(projectID) : undefined
|
||||
|
|
@ -178,26 +172,6 @@ export function createNewSessionWorkspaceController(input: {
|
|||
const projectRoot = createMemo(() => currentProject()?.worktree ?? sdk().directory)
|
||||
const branchDirectory = () => (value() === "create" ? projectRoot() : sdk().directory)
|
||||
|
||||
const [branches, branchActions] = createResource(
|
||||
() =>
|
||||
state.branchesOpen && value() === "create" && visible()
|
||||
? { directory: projectRoot(), search: state.search }
|
||||
: undefined,
|
||||
async (source) =>
|
||||
serverSDK.api.vcs.branch
|
||||
.list({ location: { directory: source.directory }, search: source.search, limit: 50 })
|
||||
.then((response) => ({ ...source, items: response.data, failed: false }))
|
||||
.catch(() => ({ ...source, items: [], failed: true })),
|
||||
)
|
||||
|
||||
// Branch search must not suspend the draft or expose another project's previous results.
|
||||
const branchResults = () => {
|
||||
if (branches.state !== "ready" && branches.state !== "refreshing") return
|
||||
const loaded = branches.latest
|
||||
|
||||
return loaded?.directory === projectRoot() && loaded.search === state.search ? loaded : undefined
|
||||
}
|
||||
|
||||
createEffect(() => {
|
||||
void Promise.all([
|
||||
data.location.syncInfo({ directory: sdk().directory }),
|
||||
|
|
@ -293,17 +267,10 @@ export function createNewSessionWorkspaceController(input: {
|
|||
visible,
|
||||
branch,
|
||||
},
|
||||
branches: {
|
||||
items: () => branchResults()?.items ?? [],
|
||||
loading: () => branches.loading,
|
||||
failed: () => branchResults()?.failed ?? false,
|
||||
search: searchBranches,
|
||||
open: (open: boolean) => {
|
||||
searchBranches.clear()
|
||||
setState({ branchesOpen: open, search: "" })
|
||||
},
|
||||
retry: () => branchActions.refetch(),
|
||||
},
|
||||
branches: (search: string, signal: AbortSignal) =>
|
||||
serverSDK.api.vcs.branch
|
||||
.list({ location: { directory: projectRoot() }, search, limit: 50 }, { signal })
|
||||
.then((response) => response.data),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,19 @@
|
|||
import { For, Show } from "solid-js"
|
||||
import { Show } from "solid-js"
|
||||
import { createStore } from "solid-js/store"
|
||||
import { Popover } from "@kobalte/core/popover"
|
||||
import { createResizeObserver } from "@solid-primitives/resize-observer"
|
||||
import { Icon } from "@opencode/ui/icon"
|
||||
import { Menu } from "@opencode/ui/menu"
|
||||
import { Tooltip } from "@opencode/ui/tooltip"
|
||||
import { Typeahead } from "@opencode/ui/typeahead"
|
||||
import { useLanguage } from "@/runtime/i18n/language"
|
||||
import type { NewSessionWorkspaceController } from "./controller"
|
||||
|
||||
export function NewSessionBranch(props: { workspace: NewSessionWorkspaceController; onDone: () => void }) {
|
||||
const language = useLanguage()
|
||||
|
||||
const [state, setState] = createStore<{ search: string; truncated: boolean; pending?: string }>({
|
||||
search: "",
|
||||
truncated: false,
|
||||
})
|
||||
const [state, setState] = createStore({ open: false, truncated: false })
|
||||
|
||||
let input: HTMLInputElement | undefined
|
||||
let outside = false
|
||||
const creating = () => props.workspace.selection.value() === "create"
|
||||
|
||||
const label = () =>
|
||||
|
|
@ -46,112 +44,53 @@ export function NewSessionBranch(props: { workspace: NewSessionWorkspaceControll
|
|||
</div>
|
||||
}
|
||||
>
|
||||
<Menu
|
||||
<Popover
|
||||
open={state.open}
|
||||
onOpenChange={(open) => setState("open", open)}
|
||||
placement="bottom-start"
|
||||
gutter={4}
|
||||
onOpenChange={(open) => {
|
||||
props.workspace.branches.open(open)
|
||||
|
||||
if (open) {
|
||||
setState({ search: "", pending: undefined })
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (state.pending) props.workspace.selection.branch(state.pending)
|
||||
setState("pending", undefined)
|
||||
props.onDone()
|
||||
}}
|
||||
>
|
||||
<Menu.Trigger class="flex h-7 min-w-0 max-w-[220px] items-center gap-1.5 rounded-sm px-1.5 text-v2-text-text-muted transition-colors hover:bg-v2-overlay-simple-overlay-hover hover:text-v2-text-text-base focus-visible:bg-v2-overlay-simple-overlay-hover focus-visible:text-v2-text-text-base focus-visible:outline-none data-[expanded]:bg-v2-overlay-simple-overlay-pressed data-[expanded]:text-v2-text-text-base">
|
||||
<Popover.Trigger class="flex h-7 min-w-0 max-w-[220px] items-center gap-1.5 rounded-sm px-1.5 text-v2-text-text-muted transition-colors hover:bg-v2-overlay-simple-overlay-hover hover:text-v2-text-text-base focus-visible:bg-v2-overlay-simple-overlay-hover focus-visible:text-v2-text-text-base focus-visible:outline-none data-[expanded]:bg-v2-overlay-simple-overlay-pressed data-[expanded]:text-v2-text-text-base">
|
||||
<Icon name="branch-out" size="small" class="shrink-0 text-v2-icon-icon-muted" />
|
||||
<span ref={observe} dir="auto" class="min-w-0 truncate">
|
||||
{label()}
|
||||
</span>
|
||||
<Icon name="chevron-down" size="small" class="-ms-0.5 shrink-0 text-v2-icon-icon-muted" />
|
||||
</Menu.Trigger>
|
||||
<Menu.Portal>
|
||||
<Menu.Content
|
||||
class="w-[243px] overflow-hidden rounded-md border-0 bg-v2-background-bg-layer-01 shadow-[var(--v2-elevation-floating)] focus:outline-none"
|
||||
onOpenAutoFocus={(event) => {
|
||||
</Popover.Trigger>
|
||||
<Popover.Portal>
|
||||
<Popover.Content
|
||||
class="w-[243px] overflow-hidden rounded-lg bg-v2-background-bg-layer-01 shadow-[var(--v2-elevation-floating)] focus:outline-none"
|
||||
onInteractOutside={() => (outside = true)}
|
||||
onCloseAutoFocus={(event) => {
|
||||
// An outside click keeps focus where the user put it.
|
||||
if (event.defaultPrevented || outside) return (outside = false)
|
||||
event.preventDefault()
|
||||
// Kobalte schedules list autofocus after the focus scope opens.
|
||||
setTimeout(() => requestAnimationFrame(() => input?.focus({ preventScroll: true })))
|
||||
props.onDone()
|
||||
}}
|
||||
>
|
||||
<div class="flex h-7 shrink-0 items-center gap-2 rounded-sm ps-3 pe-1 text-v2-icon-icon-muted">
|
||||
<Icon name="magnifying-glass" size="small" class="shrink-0" />
|
||||
<input
|
||||
ref={input}
|
||||
value={state.search}
|
||||
placeholder={language.t("session.new.workspace.branch.search.placeholder")}
|
||||
aria-label={language.t("session.new.workspace.branch.search.placeholder")}
|
||||
autocomplete="off"
|
||||
class="h-7 min-w-0 flex-1 border-0 bg-transparent text-[13px] font-[440] leading-5 tracking-[-0.04px] text-v2-text-text-base outline-none placeholder:text-v2-text-text-faint"
|
||||
onInput={(event) => {
|
||||
setState("search", event.currentTarget.value)
|
||||
props.workspace.branches.search(event.currentTarget.value)
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (["Escape", "ArrowDown", "ArrowUp", "Enter"].includes(event.key)) return
|
||||
event.stopPropagation()
|
||||
}}
|
||||
/>
|
||||
<Show when={state.search.trim()}>
|
||||
<button
|
||||
type="button"
|
||||
class="flex size-5 shrink-0 items-center justify-center rounded-sm text-v2-icon-icon-faint hover:text-v2-icon-icon-base focus-visible:text-v2-icon-icon-base"
|
||||
aria-label={language.t("common.clear")}
|
||||
onPointerDown={(event) => event.preventDefault()}
|
||||
onClick={() => {
|
||||
setState("search", "")
|
||||
props.workspace.branches.search("")
|
||||
input?.focus()
|
||||
}}
|
||||
>
|
||||
<Icon name="circle-xmark" />
|
||||
</button>
|
||||
</Show>
|
||||
</div>
|
||||
<div class="max-h-[224px] overflow-y-auto">
|
||||
<Show
|
||||
when={!props.workspace.branches.failed()}
|
||||
fallback={
|
||||
<Menu.Item closeOnSelect={false} onSelect={() => void props.workspace.branches.retry()}>
|
||||
{language.t("common.retry")}
|
||||
</Menu.Item>
|
||||
}
|
||||
>
|
||||
<Show
|
||||
when={props.workspace.branches.items().length > 0}
|
||||
fallback={
|
||||
<div class="px-3 py-2 text-v2-text-text-faint">
|
||||
{language.t(props.workspace.branches.loading() ? "common.loading" : "palette.empty")}
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<Menu.RadioGroup value={props.workspace.bar.branch()}>
|
||||
<For each={props.workspace.branches.items()}>
|
||||
{(branch) => (
|
||||
<Menu.RadioItem
|
||||
value={branch}
|
||||
closeOnSelect
|
||||
class="h-7 gap-2 rounded-sm px-3 text-[13px] font-[440] leading-5 tracking-[-0.04px] text-v2-text-text-base data-[highlighted]:!bg-v2-overlay-simple-overlay-hover"
|
||||
onSelect={() => setState("pending", branch)}
|
||||
>
|
||||
<span dir="auto" class="min-w-0 truncate leading-5">
|
||||
{branch}
|
||||
</span>
|
||||
</Menu.RadioItem>
|
||||
)}
|
||||
</For>
|
||||
</Menu.RadioGroup>
|
||||
</Show>
|
||||
</Show>
|
||||
</div>
|
||||
</Menu.Content>
|
||||
</Menu.Portal>
|
||||
</Menu>
|
||||
<Typeahead
|
||||
placeholder={language.t("session.new.workspace.branch.search.placeholder")}
|
||||
emptyLabel={language.t("palette.empty")}
|
||||
retryLabel={language.t("common.retry")}
|
||||
source={props.workspace.branches}
|
||||
match={(branch, query) => branch.toLowerCase().includes(query.toLowerCase())}
|
||||
delay={100}
|
||||
key={(branch) => branch}
|
||||
selected={props.workspace.bar.branch()}
|
||||
onSelect={(branch) => {
|
||||
props.workspace.selection.branch(branch)
|
||||
setState("open", false)
|
||||
}}
|
||||
>
|
||||
{(branch) => (
|
||||
<span dir="auto" class="min-w-0 truncate">
|
||||
{branch}
|
||||
</span>
|
||||
)}
|
||||
</Typeahead>
|
||||
</Popover.Content>
|
||||
</Popover.Portal>
|
||||
</Popover>
|
||||
</Show>
|
||||
</Tooltip>
|
||||
</Show>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { Dialog, DialogBody } from "@opencode/ui/dialog"
|
|||
import { Icon } from "@opencode/ui/icon"
|
||||
import { Keybind } from "@opencode/ui/keybind"
|
||||
import { TextInput } from "@opencode/ui/text-input"
|
||||
import { createTypeahead } from "@opencode/ui/typeahead"
|
||||
import { createEffect, createMemo, For, Match, onCleanup, Show, Switch } from "solid-js"
|
||||
import { createStore } from "solid-js/store"
|
||||
import { formatKeybindParts } from "@/shell/commands/command"
|
||||
|
|
@ -65,7 +66,7 @@ export function CommandPaletteView(props: {
|
|||
}) {
|
||||
const language = useLanguage()
|
||||
const tabs = useTabs()
|
||||
const [store, setStore] = createStore<{ query: string; active?: string }>({ query: "" })
|
||||
const [store, setStore] = createStore({ query: "" })
|
||||
|
||||
const search = createCommandPaletteSearch({ query: () => store.query, items: props.items, sources: props.sources })
|
||||
const visibleEntries = search.items
|
||||
|
|
@ -78,9 +79,14 @@ export function CommandPaletteView(props: {
|
|||
})
|
||||
|
||||
// Follow the first result until the user explicitly chooses a row.
|
||||
const activeEntry = createMemo(
|
||||
() => visibleEntries().find((entry) => entry.id === store.active) ?? visibleEntries()[0],
|
||||
)
|
||||
const typeahead = createTypeahead<CommandPaletteEntry>({
|
||||
items: visibleEntries,
|
||||
key: (entry) => entry.id,
|
||||
onSelect: props.select,
|
||||
onClose: props.close,
|
||||
})
|
||||
|
||||
const activeEntry = typeahead.activeItem
|
||||
|
||||
const openSessions = createMemo(
|
||||
() => new Set(tabs.store.flatMap((tab) => (tab.type === "session" ? [`${tab.server}\0${tab.sessionId}`] : []))),
|
||||
|
|
@ -105,42 +111,6 @@ export function CommandPaletteView(props: {
|
|||
onCleanup(() => cancelAnimationFrame(frame))
|
||||
})
|
||||
|
||||
const move = (delta: -1 | 1) => {
|
||||
const count = visibleEntries().length
|
||||
|
||||
if (count === 0) return
|
||||
const index = visibleEntries().findIndex((entry) => entry.id === activeEntry()?.id)
|
||||
setStore("active", visibleEntries()[(index + delta + count) % count].id)
|
||||
}
|
||||
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key === "ArrowDown") {
|
||||
event.preventDefault()
|
||||
move(1)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (event.key === "ArrowUp") {
|
||||
event.preventDefault()
|
||||
move(-1)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault()
|
||||
props.select(activeEntry())
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (event.key === "Escape") {
|
||||
event.preventDefault()
|
||||
props.close()
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog class="command-palette" size="large">
|
||||
<DialogBody class="command-palette-body">
|
||||
|
|
@ -153,19 +123,16 @@ export function CommandPaletteView(props: {
|
|||
appearance="large"
|
||||
placeholder={props.placeholder}
|
||||
leadingIcon={<Icon name="magnifying-glass" />}
|
||||
onInput={(event) => {
|
||||
const query = event.currentTarget.value
|
||||
const active = store.active ? entryById().get(store.active) : undefined
|
||||
setStore({
|
||||
query,
|
||||
active: active && matchesCommandPaletteEntry(active, query) ? store.active : undefined,
|
||||
})
|
||||
}}
|
||||
onKeyDown={handleKeyDown}
|
||||
role="combobox"
|
||||
aria-expanded="true"
|
||||
aria-controls={typeahead.listID}
|
||||
aria-activedescendant={typeahead.activeID()}
|
||||
onInput={(event) => setStore("query", event.currentTarget.value)}
|
||||
onKeyDown={typeahead.onKeyDown}
|
||||
/>
|
||||
</div>
|
||||
<ScrollView class="command-palette-scroll" viewportRef={(el) => (resultsRef = el)}>
|
||||
<div class="command-palette-results" role="listbox">
|
||||
<div id={typeahead.listID} class="command-palette-results" role="listbox">
|
||||
<Show
|
||||
when={visibleEntries().length > 0}
|
||||
fallback={
|
||||
|
|
@ -202,6 +169,7 @@ export function CommandPaletteView(props: {
|
|||
|
||||
return (
|
||||
<PaletteRow
|
||||
id={typeahead.optionID(item())}
|
||||
item={item()}
|
||||
active={activeEntry()?.id === id}
|
||||
language={language}
|
||||
|
|
@ -210,7 +178,7 @@ export function CommandPaletteView(props: {
|
|||
? openSessions().has(`${item().server}\0${item().sessionID}`)
|
||||
: false
|
||||
}
|
||||
onActive={() => setStore("active", id)}
|
||||
onActive={() => typeahead.setActive(id)}
|
||||
onSelect={() => props.select(item())}
|
||||
/>
|
||||
)
|
||||
|
|
@ -229,6 +197,7 @@ export function CommandPaletteView(props: {
|
|||
}
|
||||
|
||||
function PaletteRow(props: {
|
||||
id: string
|
||||
item: CommandPaletteEntry
|
||||
active: boolean
|
||||
language: ReturnType<typeof useLanguage>
|
||||
|
|
@ -243,6 +212,7 @@ function PaletteRow(props: {
|
|||
|
||||
return (
|
||||
<button
|
||||
id={props.id}
|
||||
type="button"
|
||||
class="command-palette-row group"
|
||||
role="option"
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@
|
|||
"./text-input": "./src/forms/text-input/text-input.tsx",
|
||||
"./text-input.css": "./src/forms/text-input/text-input.css",
|
||||
"./textarea": "./src/forms/textarea/textarea.tsx",
|
||||
"./typeahead": "./src/forms/typeahead/typeahead.tsx",
|
||||
"./text-shimmer": "./src/typography/text-shimmer/text-shimmer.tsx",
|
||||
"./toast": "./src/feedback/toast/toast.tsx",
|
||||
"./tooltip": "./src/overlays/tooltip/tooltip.tsx",
|
||||
|
|
|
|||
57
packages/ui/src/forms/typeahead/controller.ts
Normal file
57
packages/ui/src/forms/typeahead/controller.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import { createEffect, createMemo, createUniqueId } from "solid-js"
|
||||
import { createStore } from "solid-js/store"
|
||||
|
||||
/** The active row, keys and combobox ids for a search input above a list of options. */
|
||||
export function createTypeahead<T>(props: {
|
||||
items: () => T[]
|
||||
key: (item: T) => string
|
||||
/** Rows on screen that the current query has not confirmed. The user's choice never rests on one. */
|
||||
stale?: (item: T) => boolean
|
||||
onSelect: (item: T) => void
|
||||
onClose?: () => void
|
||||
}) {
|
||||
const id = createUniqueId()
|
||||
const [store, setStore] = createStore<{ active?: string }>({})
|
||||
const chosen = () => props.items().find((item) => props.key(item) === store.active && !props.stale?.(item))
|
||||
|
||||
// The user's choice holds while it is among the confirmed rows; once it leaves, the first row is active again.
|
||||
createEffect(() => {
|
||||
if (store.active !== undefined && chosen() === undefined) setStore("active", undefined)
|
||||
})
|
||||
|
||||
const activeItem = createMemo(() => chosen() ?? props.items()[0])
|
||||
const optionID = (item: T) => `${id}-${encodeURIComponent(props.key(item))}`
|
||||
|
||||
return {
|
||||
activeItem,
|
||||
setActive: (key: string | undefined) => setStore("active", key),
|
||||
listID: `${id}-list`,
|
||||
optionID,
|
||||
activeID: () => {
|
||||
const item = activeItem()
|
||||
|
||||
return item === undefined ? undefined : optionID(item)
|
||||
},
|
||||
onKeyDown: (event: KeyboardEvent) => {
|
||||
if (event.isComposing) return
|
||||
const items = props.items()
|
||||
const delta = event.key === "ArrowDown" ? 1 : event.key === "ArrowUp" ? -1 : 0
|
||||
|
||||
if (delta !== 0 || event.key === "Enter" || (event.key === "Escape" && props.onClose)) {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
}
|
||||
|
||||
if (delta !== 0 && items.length > 0) {
|
||||
const index = items.findIndex((item) => item === activeItem())
|
||||
setStore("active", props.key(items[(index + delta + items.length) % items.length]))
|
||||
}
|
||||
|
||||
const item = activeItem()
|
||||
|
||||
if (event.key === "Enter" && item !== undefined) props.onSelect(item)
|
||||
|
||||
if (event.key === "Escape") props.onClose?.()
|
||||
},
|
||||
}
|
||||
}
|
||||
199
packages/ui/src/forms/typeahead/typeahead.tsx
Normal file
199
packages/ui/src/forms/typeahead/typeahead.tsx
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
import { createResizeObserver } from "@solid-primitives/resize-observer"
|
||||
import { createEffect, createMemo, For, type JSX, onCleanup, Show } from "solid-js"
|
||||
import { createStore } from "solid-js/store"
|
||||
import { Icon } from "@opencode/ui/icon"
|
||||
import { useI18n } from "../../context/i18n"
|
||||
import { Spinner } from "../../components/spinner"
|
||||
import { createTypeahead } from "./controller"
|
||||
|
||||
export { createTypeahead } from "./controller"
|
||||
|
||||
/** A search field over results from `source` that keeps rows on screen while a query is pending. */
|
||||
export function Typeahead<T>(props: {
|
||||
source: (query: string, signal: AbortSignal) => Promise<T[]>
|
||||
/** Narrows earlier results while the request for the current query is pending. */
|
||||
match: (item: T, query: string) => boolean
|
||||
key: (item: T) => string
|
||||
/** Milliseconds a typed query waits before it reaches the source. */
|
||||
delay: number
|
||||
placeholder: string
|
||||
emptyLabel: string
|
||||
retryLabel: string
|
||||
/** Key of the current value. */
|
||||
selected?: string
|
||||
onSelect: (item: T) => void
|
||||
children: (item: T) => JSX.Element
|
||||
}) {
|
||||
const i18n = useI18n()
|
||||
|
||||
const [store, setStore] = createStore<{ query: string; answered?: string; failed?: boolean; loading?: boolean }>({
|
||||
query: "",
|
||||
})
|
||||
|
||||
const cache = new Map<string, T[]>()
|
||||
let seen: T[] = []
|
||||
let abort: AbortController | undefined
|
||||
let input: HTMLInputElement | undefined
|
||||
onCleanup(() => abort?.abort())
|
||||
|
||||
const query = () => store.query.trim()
|
||||
const pending = () => store.loading || store.answered !== query()
|
||||
|
||||
const search = (query: string) => {
|
||||
abort?.abort()
|
||||
|
||||
if (cache.has(query)) return setStore({ answered: query, failed: false, loading: false })
|
||||
const current = (abort = new AbortController())
|
||||
setStore("loading", true)
|
||||
props.source(query, current.signal).then(
|
||||
(items) => {
|
||||
if (current.signal.aborted) return
|
||||
const keys = new Set(items.map(props.key))
|
||||
cache.set(query, items)
|
||||
seen = [...items, ...seen.filter((item) => !keys.has(props.key(item)))].slice(0, 500)
|
||||
setStore({ answered: query, failed: false, loading: false })
|
||||
},
|
||||
() => !current.signal.aborted && setStore({ answered: query, failed: true, loading: false }),
|
||||
)
|
||||
}
|
||||
|
||||
// A cached or empty query answers at once; a typed one waits, and the request it supersedes is aborted.
|
||||
createEffect(() => {
|
||||
const next = query()
|
||||
|
||||
if (!next || cache.has(next)) return search(next)
|
||||
abort?.abort()
|
||||
const timer = setTimeout(() => search(next), props.delay)
|
||||
onCleanup(() => clearTimeout(timer))
|
||||
})
|
||||
|
||||
// While a query is pending: its cached answer, else earlier rows that match it, else the rows on screen, marked stale.
|
||||
const results = createMemo<{ items: T[]; stale: boolean }>((previous) => {
|
||||
const next = query()
|
||||
|
||||
if (store.answered === next && store.failed) return { items: [], stale: false }
|
||||
const cached = cache.get(next) ?? seen.filter((item) => props.match(item, next))
|
||||
|
||||
if (cache.has(next) || cached.length > 0) return { items: cached, stale: false }
|
||||
|
||||
return { items: previous?.items ?? [], stale: !!previous?.items.length }
|
||||
})
|
||||
|
||||
const typeahead = createTypeahead<T>({
|
||||
items: () => results().items,
|
||||
key: (item) => props.key(item),
|
||||
stale: () => results().stale,
|
||||
onSelect: (item) => props.onSelect(item),
|
||||
})
|
||||
|
||||
createEffect(() => {
|
||||
const id = typeahead.activeID()
|
||||
|
||||
if (id) document.getElementById(id)?.scrollIntoView({ block: "nearest" })
|
||||
})
|
||||
|
||||
return (
|
||||
<div class="flex min-w-0 flex-col text-[13px] font-[440] leading-text-compact tracking-[-0.04px] text-v2-text-text-base">
|
||||
<div class="flex h-8 shrink-0 items-center gap-2 ps-3 pe-2">
|
||||
{/* The spinner shares the glyph's slot and fades in only for requests slower than 150 ms. */}
|
||||
<span
|
||||
data-pending={pending() ? "" : undefined}
|
||||
aria-hidden="true"
|
||||
class="group grid size-3.5 shrink-0 place-items-center text-v2-icon-icon-muted *:[grid-area:1/1] *:transition-opacity *:duration-150 data-[pending]:*:delay-150"
|
||||
>
|
||||
<Icon name="magnifying-glass" size="small" class="group-data-[pending]:opacity-0" />
|
||||
<Spinner class="w-3 opacity-0 group-data-[pending]:opacity-100" />
|
||||
</span>
|
||||
<input
|
||||
ref={input}
|
||||
role="combobox"
|
||||
aria-expanded="true"
|
||||
aria-controls={typeahead.listID}
|
||||
aria-autocomplete="list"
|
||||
aria-busy={pending()}
|
||||
aria-activedescendant={typeahead.activeID()}
|
||||
aria-label={props.placeholder}
|
||||
placeholder={props.placeholder}
|
||||
value={store.query}
|
||||
autocomplete="off"
|
||||
spellcheck={false}
|
||||
class="h-8 min-w-0 flex-1 outline-none placeholder:text-v2-text-text-faint"
|
||||
onInput={(event) => setStore("query", event.currentTarget.value)}
|
||||
onKeyDown={typeahead.onKeyDown}
|
||||
/>
|
||||
<Show when={store.query}>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={i18n.t("ui.list.clearFilter")}
|
||||
class="flex size-5 shrink-0 items-center justify-center rounded-sm text-v2-icon-icon-faint outline-none hover:text-v2-icon-icon-base focus-visible:text-v2-icon-icon-base"
|
||||
onPointerDown={(event) => event.preventDefault()}
|
||||
onClick={() => {
|
||||
setStore("query", "")
|
||||
input?.focus()
|
||||
}}
|
||||
>
|
||||
<Icon name="circle-xmark" size="small" />
|
||||
</button>
|
||||
</Show>
|
||||
</div>
|
||||
{/* Height follows the results on a critically damped spring (0.3 s, bounce 0); the first measurement snaps. */}
|
||||
<div class="overflow-hidden transition-[height] duration-[350ms] ease-[linear(0,0.097,0.282,0.466,0.619,0.736,0.821,0.881,0.921,0.949,0.967,0.979,0.986,0.991,1)] motion-reduce:transition-none">
|
||||
<div
|
||||
ref={(element) =>
|
||||
createResizeObserver(element, (rect) =>
|
||||
element.parentElement?.style.setProperty("height", `${rect.height}px`),
|
||||
)
|
||||
}
|
||||
>
|
||||
<div
|
||||
id={typeahead.listID}
|
||||
role="listbox"
|
||||
class="max-h-56 overflow-y-auto px-1 pb-1 [scrollbar-width:thin] empty:hidden"
|
||||
>
|
||||
<For each={results().items}>
|
||||
{(item) => (
|
||||
<div
|
||||
id={typeahead.optionID(item)}
|
||||
role="option"
|
||||
aria-selected={typeahead.activeItem() === item}
|
||||
aria-current={props.selected === props.key(item) ? "true" : undefined}
|
||||
class="flex h-7 min-w-0 cursor-default select-none items-center gap-2 rounded-sm px-2 transition-opacity duration-150 aria-selected:bg-v2-overlay-simple-overlay-hover"
|
||||
classList={{ "opacity-50": results().stale }}
|
||||
onMouseMove={(event) => {
|
||||
// A static cursor must not steal the active row while the keyboard scrolls the list.
|
||||
if (event.movementX !== 0 || event.movementY !== 0) typeahead.setActive(props.key(item))
|
||||
}}
|
||||
onMouseDown={(event) => event.preventDefault()}
|
||||
onClick={() => props.onSelect(item)}
|
||||
>
|
||||
{props.children(item)}
|
||||
<Show when={props.selected === props.key(item)}>
|
||||
<Icon name="check" size="small" class="ms-auto shrink-0 text-v2-icon-icon-muted" />
|
||||
</Show>
|
||||
</div>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
{/* Stays mounted while a retry or a newer query is pending, so the list never collapses to nothing. */}
|
||||
<Show when={results().items.length === 0}>
|
||||
<div
|
||||
class="mx-1 mb-1 flex h-7 items-center px-2 text-v2-text-text-faint"
|
||||
classList={{ invisible: store.answered === undefined }}
|
||||
>
|
||||
<Show when={store.failed} fallback={props.emptyLabel}>
|
||||
<button
|
||||
type="button"
|
||||
class="-mx-2 flex h-7 flex-1 items-center rounded-sm px-2 text-start text-v2-text-text-base outline-none hover:bg-v2-overlay-simple-overlay-hover focus-visible:bg-v2-overlay-simple-overlay-hover"
|
||||
onMouseDown={(event) => event.preventDefault()}
|
||||
onClick={() => search(query())}
|
||||
>
|
||||
{props.retryLabel}
|
||||
</button>
|
||||
</Show>
|
||||
</div>
|
||||
</Show>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue