mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 17:01:37 +03:00
feat(app): align search and command palettes (#59604)
This commit is contained in:
committed by
GitHub
Unverified
parent
d012e07e63
commit
7b1e54a74f
@@ -619,18 +619,61 @@ test("keeps matching session and file results steady across keystrokes while sea
|
||||
})
|
||||
})
|
||||
|
||||
test("keeps the same height as the number of results changes", async ({ page }) => {
|
||||
const { dialog, input } = await openCommandPalette(page)
|
||||
test("titlebar session search shrinks with results while its field stays anchored through scrolling", async ({
|
||||
page,
|
||||
}) => {
|
||||
await openPaletteWorkspace(page, true, [
|
||||
{ ...paletteSession, time: { ...paletteSession.time } },
|
||||
...Array.from({ length: 23 }, (_, index) => ({
|
||||
...paletteSession,
|
||||
id: `ses_compact_palette_${index}`,
|
||||
title: index === 0 ? "Compact keeper needle" : `Compact keeper result ${index}`,
|
||||
time: { created: 1700000000000 - index - 1, updated: 1700000000000 - index - 1 },
|
||||
})),
|
||||
])
|
||||
await page.getByRole("banner").getByRole("button", { name: "Search sessions", exact: true }).click()
|
||||
const dialog = page.getByRole("dialog")
|
||||
const input = dialog.getByRole("combobox")
|
||||
const options = dialog.getByRole("option")
|
||||
const container = page.locator('[data-component="dialog-v2"] [data-slot="dialog-container"]')
|
||||
const height = async () => (await container.boundingBox())?.height
|
||||
const initial = await height()
|
||||
expect(initial).toBe(480)
|
||||
|
||||
await input.fill("copy session")
|
||||
await expect(dialog.getByRole("option")).toHaveCount(1)
|
||||
expect(await height()).toBe(initial)
|
||||
const geometry = () =>
|
||||
container.evaluate((element) => ({
|
||||
height: element.getBoundingClientRect().height,
|
||||
inputTop: element.querySelector('[role="combobox"]')!.getBoundingClientRect().top,
|
||||
}))
|
||||
|
||||
await input.fill("zzzz no palette match")
|
||||
await expect(dialog.getByText("No results found")).toBeVisible()
|
||||
expect(await height()).toBe(initial)
|
||||
await expect(input).toBeFocused()
|
||||
await expect(options).toHaveCount(10)
|
||||
// Hover waits for the field's opening animation to settle before taking the reference position.
|
||||
await input.hover()
|
||||
const initial = await geometry()
|
||||
expect(initial.height).toBeGreaterThan(200)
|
||||
|
||||
await input.fill("Compact keeper needle")
|
||||
await expect(options).toHaveText([/Compact keeper needle/])
|
||||
await expect.poll(async () => (await geometry()).height).toBeLessThan(initial.height - 100)
|
||||
await expect.poll(async () => (await geometry()).inputTop).toBeCloseTo(initial.inputTop, 0)
|
||||
|
||||
await input.clear()
|
||||
await expect(options).toHaveCount(10)
|
||||
await expect.poll(geometry).toEqual({
|
||||
height: expect.closeTo(initial.height, 0),
|
||||
inputTop: expect.closeTo(initial.inputTop, 0),
|
||||
})
|
||||
|
||||
// A broader query exposes more than the recent-session limit and must scroll below the field.
|
||||
await input.fill("Compact keeper")
|
||||
await expect(options).toHaveCount(23)
|
||||
const scroll = dialog.locator('[data-slot="search-list-scroll"]')
|
||||
await expect.poll(() => scroll.evaluate((element) => element.scrollHeight - element.clientHeight)).toBeGreaterThan(0)
|
||||
await expect.poll(async () => (await geometry()).height).toBeLessThanOrEqual(480)
|
||||
const last = dialog.getByRole("option", { name: /Compact keeper result 22/ })
|
||||
await expect(last).not.toBeInViewport()
|
||||
await scroll.hover()
|
||||
await page.mouse.wheel(0, 2000)
|
||||
await expect(last).toBeInViewport()
|
||||
await expect.poll(() => scroll.evaluate((element) => element.scrollTop)).toBeGreaterThan(0)
|
||||
await expect.poll(async () => (await geometry()).inputTop).toBeCloseTo(initial.inputTop, 0)
|
||||
await expect(input).toBeFocused()
|
||||
})
|
||||
|
||||
@@ -365,7 +365,7 @@ function NewSessionLocation(props: {
|
||||
{(directory) => (
|
||||
<div
|
||||
class="flex min-w-0 flex-1 justify-end pe-1.5 @max-[560px]:hidden"
|
||||
style={{ "min-width": `min(calc(100% - 12px), ${Math.ceil(fitted().minimum) + 26}px)` }}
|
||||
style={{ "min-width": `min(50%, ${Math.ceil(fitted().minimum) + 26}px)` }}
|
||||
>
|
||||
<Tooltip
|
||||
placement="top"
|
||||
|
||||
@@ -135,3 +135,128 @@
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
/* Like the project picker, results grow down from a stable search-field anchor. Other picker dialogs keep their layout. */
|
||||
[data-component="dialog-v2"]:has(.command-palette-compact) {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
[data-component="dialog-v2"]:has(.command-palette-compact) [data-slot="dialog-container"] {
|
||||
width: min(calc(100vw - 24px), 480px);
|
||||
height: auto;
|
||||
max-height: min(calc(100vh - 96px), 480px);
|
||||
min-height: 0;
|
||||
margin-top: max(48px, calc((100vh - 480px) / 2));
|
||||
background: var(--v2-background-bg-layer-01);
|
||||
box-shadow: var(--v2-elevation-overlay);
|
||||
}
|
||||
|
||||
.command-palette-compact {
|
||||
[data-slot="search-list-search"] {
|
||||
position: relative;
|
||||
padding: 6px 6px 17px;
|
||||
|
||||
&::after {
|
||||
position: absolute;
|
||||
inset-inline: 0;
|
||||
bottom: 8px;
|
||||
border-top: 0.5px solid var(--v2-border-border-base);
|
||||
content: "";
|
||||
}
|
||||
|
||||
[data-component="text-input-v2"] {
|
||||
height: 28px;
|
||||
padding-inline-end: 6px;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
[data-component="text-input-v2"]:where(:hover, :focus-within):not([data-disabled], [data-invalid]) {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
[data-slot="text-input-v2-value"] {
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
[data-slot="text-input-v2-leading-icon"] {
|
||||
padding-inline-start: 6px;
|
||||
}
|
||||
|
||||
[data-slot="text-input-v2-input"]::placeholder {
|
||||
color: var(--v2-text-text-base);
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="search-list-results"] {
|
||||
padding: 0 6px 6px;
|
||||
}
|
||||
|
||||
[data-slot="search-list-section"] {
|
||||
gap: 4px;
|
||||
|
||||
&:not(:last-child) {
|
||||
padding-bottom: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="search-list-header"] {
|
||||
padding-inline: 12px;
|
||||
background: var(--v2-background-bg-layer-01);
|
||||
}
|
||||
|
||||
[data-slot="search-list-fade"]::before {
|
||||
background: linear-gradient(var(--v2-background-bg-layer-01), transparent);
|
||||
}
|
||||
|
||||
[data-slot="search-list-row"] {
|
||||
padding-inline: 6px;
|
||||
|
||||
&:is([data-active], :focus-visible) {
|
||||
background: var(--v2-overlay-simple-overlay-hover);
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
|
||||
.command-palette-row-text {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.command-palette-row-text:has(.command-palette-description) > .command-palette-title {
|
||||
max-width: 60%;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.command-palette-description {
|
||||
flex: 1;
|
||||
color: var(--v2-text-text-faint);
|
||||
}
|
||||
}
|
||||
|
||||
[data-color-scheme="dark"] .command-palette-compact [data-slot="search-list-row"]:is([data-active], :focus-visible) {
|
||||
background: var(--v2-overlay-simple-overlay-hover);
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.command-palette-compact {
|
||||
[data-slot="search-list-row"]:has(.command-palette-description) {
|
||||
min-height: 40px;
|
||||
}
|
||||
|
||||
.command-palette-row-text:has(.command-palette-description) > .command-palette-title {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.command-palette-description {
|
||||
flex: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (pointer: coarse) {
|
||||
.command-palette-compact [data-slot="search-list-row"],
|
||||
.command-palette-compact [data-slot="search-list-row"]:has(.command-palette-description),
|
||||
.command-palette-compact [data-slot="search-list-search"] [data-component="text-input-v2"] {
|
||||
min-height: 44px;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ export function CommandPaletteView(props: {
|
||||
})
|
||||
|
||||
return (
|
||||
<Dialog class="command-palette" size="large">
|
||||
<Dialog class="command-palette command-palette-compact" size="large" fit>
|
||||
<DialogBody class="command-palette-body">
|
||||
<SearchList
|
||||
query={store.query}
|
||||
@@ -122,12 +122,12 @@ function PaletteRow(props: {
|
||||
: undefined
|
||||
|
||||
return (
|
||||
<button type="button" class="command-palette-row group" {...props.row}>
|
||||
<button type="button" class="command-palette-row group" data-size="compact" {...props.row}>
|
||||
<Switch
|
||||
fallback={
|
||||
<div class="command-palette-row-main">
|
||||
<FileIcon node={{ path: props.item.path ?? "", type: "file" }} class="command-palette-row-icon size-4" />
|
||||
<div class="command-palette-file-path">
|
||||
<div class="command-palette-file-path" dir="ltr">
|
||||
<span class="command-palette-file-dir">
|
||||
<SearchHighlight text={getDirectory(props.item.path ?? "")} />
|
||||
</span>
|
||||
@@ -141,12 +141,12 @@ function PaletteRow(props: {
|
||||
<Match when={props.item.type === "command" || props.item.type === "setting"}>
|
||||
<div class="command-palette-row-main">
|
||||
<div class="command-palette-row-text">
|
||||
<span class="command-palette-title palette-menu-title">
|
||||
<span class="command-palette-title palette-menu-title" dir="auto">
|
||||
<SearchHighlight text={props.item.title} />
|
||||
</span>
|
||||
<Show when={props.item.description}>
|
||||
{(description) => (
|
||||
<span class="command-palette-description">
|
||||
<span class="command-palette-description" dir="auto">
|
||||
<SearchHighlight text={description()} />
|
||||
</span>
|
||||
)}
|
||||
@@ -164,7 +164,7 @@ function PaletteRow(props: {
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="pointer-events-none absolute top-1/2 h-3 w-0.5 -translate-y-1/2 rounded-[2px] bg-v2-background-bg-layer-04"
|
||||
style={{ right: "calc(100% + 4px)" }}
|
||||
style={{ "inset-inline-start": "-6px" }}
|
||||
/>
|
||||
</Show>
|
||||
<Show when={session()}>
|
||||
@@ -181,13 +181,18 @@ function PaletteRow(props: {
|
||||
<div class="command-palette-row-text">
|
||||
<span
|
||||
class="command-palette-title palette-menu-title"
|
||||
dir="auto"
|
||||
classList={{ "opacity-70": !!props.item.archived }}
|
||||
>
|
||||
<SearchHighlight text={props.item.title} />
|
||||
</span>
|
||||
<Show when={props.item.description}>
|
||||
{(description) => (
|
||||
<span class="command-palette-description" classList={{ "opacity-70": !!props.item.archived }}>
|
||||
<span
|
||||
class="command-palette-description"
|
||||
dir="auto"
|
||||
classList={{ "opacity-70": !!props.item.archived }}
|
||||
>
|
||||
<SearchHighlight text={description()} />
|
||||
</span>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user