mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 13:05:14 +03:00
feat(app): find settings from the command palette (#57651)
This commit is contained in:
committed by
GitHub
Unverified
parent
899ccee996
commit
b58bd26132
@@ -43,6 +43,42 @@ test("home commands do not wait for session search", async ({ page }) => {
|
||||
release.resolve()
|
||||
})
|
||||
|
||||
test("finds a setting and opens Settings with its row in view and highlighted", async ({ page }) => {
|
||||
await openPaletteWorkspace(page)
|
||||
await page.keyboard.press("Control+K")
|
||||
const dialog = page.getByRole("dialog")
|
||||
const input = dialog.getByRole("combobox")
|
||||
await expect(input).toBeFocused()
|
||||
await input.fill("theme")
|
||||
await expect(dialog.getByRole("option", { name: /^Theme/ })).toHaveAttribute("aria-selected", "true")
|
||||
|
||||
// Settings list after commands, and the keyboard walks rows in their visual order.
|
||||
const searched = Promise.all([
|
||||
page.waitForResponse((response) => new URL(response.url()).pathname === "/api/session"),
|
||||
page.waitForResponse((response) => new URL(response.url()).pathname === "/api/fs/find"),
|
||||
])
|
||||
|
||||
await input.fill("model")
|
||||
await searched
|
||||
const titles = dialog.locator(".command-palette-group-title")
|
||||
await expect(titles.first()).toHaveText("Commands")
|
||||
await expect(titles.last()).toHaveText("Settings")
|
||||
const options = dialog.getByRole("option")
|
||||
|
||||
for (const index of Array.from({ length: await options.count() }, (_, index) => index)) {
|
||||
await expect(options.nth(index)).toHaveAttribute("aria-selected", "true")
|
||||
await input.press("ArrowDown")
|
||||
}
|
||||
|
||||
await input.fill("theme")
|
||||
await expect(dialog.getByRole("option", { name: /^Theme/ })).toHaveAttribute("aria-selected", "true")
|
||||
await input.press("Enter")
|
||||
await expect(page).toHaveURL("/settings?tab=appearance")
|
||||
const row = page.getByTestId("settings-screen").locator('[data-search-target="row"]')
|
||||
await expect(row).toContainText("Theme")
|
||||
await expect(row).toBeInViewport()
|
||||
})
|
||||
|
||||
test("lists recent sessions before a query is entered", async ({ page }) => {
|
||||
const { dialog } = await openCommandPalette(page, true)
|
||||
const session = dialog.getByRole("option", { name: /Palette fixture session/ })
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
type PaletteHighlight,
|
||||
} from "@/shell/commands/palette"
|
||||
import { CommandPaletteView, matchesCommandPaletteEntry } from "@/shell/commands/dialog"
|
||||
import { createSettingsPaletteEntries } from "@/settings/palette"
|
||||
|
||||
export function HomeCommandPalette(props: {
|
||||
server: ServerConnection.Any
|
||||
@@ -23,6 +24,7 @@ export function HomeCommandPalette(props: {
|
||||
const language = useLanguage()
|
||||
const server = global.ensureServerCtx(props.server)
|
||||
const state: PaletteHighlight = { cleanup: undefined, committed: false }
|
||||
const settings = createSettingsPaletteEntries()
|
||||
|
||||
const commandEntries = createMemo(() => {
|
||||
const category = language.t("palette.group.commands")
|
||||
@@ -62,6 +64,8 @@ export function HomeCommandPalette(props: {
|
||||
}
|
||||
|
||||
if (item.type === "session") props.onSelectSession(item)
|
||||
|
||||
if (item.type === "setting") settings.select(item)
|
||||
}
|
||||
|
||||
const items = (query: string) => {
|
||||
@@ -70,6 +74,7 @@ export function HomeCommandPalette(props: {
|
||||
return [
|
||||
...commandEntries().filter((entry) => matchesCommandPaletteEntry(entry, query)),
|
||||
...sessions.items(query),
|
||||
...settings.items(query),
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@ export const dict = {
|
||||
"palette.group.commands": "Commands",
|
||||
"palette.group.files": "Files",
|
||||
"palette.group.recentSessions": "Recent sessions",
|
||||
"palette.group.settings": "Settings",
|
||||
"palette.session.location": "{{project}} · {{server}}",
|
||||
|
||||
"dialog.provider.search.placeholder": "Search providers",
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { createMemo } from "solid-js"
|
||||
import { useLanguage } from "@/runtime/i18n/language"
|
||||
import type { CommandPaletteEntry } from "@/shell/commands/palette"
|
||||
import { createSettingsSearchCatalog } from "./search"
|
||||
import { rankSettings } from "./search-results"
|
||||
import { useSettingsSurface } from "./surface"
|
||||
|
||||
const LIMIT = 5
|
||||
|
||||
/** Settings rows for the command palette; selecting one opens Settings at that row. */
|
||||
export function createSettingsPaletteEntries() {
|
||||
const language = useLanguage()
|
||||
const surface = useSettingsSurface()
|
||||
const catalog = createSettingsSearchCatalog()
|
||||
// Servers and projects already have their own palette rows.
|
||||
const settings = createMemo(() => catalog().filter((item) => !item.entity))
|
||||
|
||||
return {
|
||||
items(query: string): CommandPaletteEntry[] {
|
||||
const value = query.trim().toLocaleLowerCase()
|
||||
const category = language.t("palette.group.settings")
|
||||
|
||||
// A title that starts with the query leads the group.
|
||||
return rankSettings(value, settings())
|
||||
.toSorted(
|
||||
(a, b) =>
|
||||
Number(b.title.toLocaleLowerCase().startsWith(value)) -
|
||||
Number(a.title.toLocaleLowerCase().startsWith(value)),
|
||||
)
|
||||
.slice(0, LIMIT)
|
||||
.map((item) => ({
|
||||
id: `setting:${item.id}`,
|
||||
type: "setting",
|
||||
title: item.title,
|
||||
description: item.page === item.title ? undefined : item.page,
|
||||
category,
|
||||
setting: item,
|
||||
}))
|
||||
},
|
||||
select(entry: CommandPaletteEntry) {
|
||||
if (entry.setting) surface.search.open(entry.setting.view, entry.setting.id)
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -76,6 +76,13 @@ export const clientSettings: Entry<SettingsRootTab>[] = [
|
||||
section: "settings.timeline.title",
|
||||
keywords: "capsule panel subagent shell background activity position alignment hidden left center right",
|
||||
},
|
||||
{
|
||||
tab: "general",
|
||||
label: "settings.timeline.row.turnDiffs.title",
|
||||
description: "settings.timeline.row.turnDiffs.description",
|
||||
target: "settings-show-turn-diffs",
|
||||
section: "settings.timeline.title",
|
||||
},
|
||||
{
|
||||
tab: "general",
|
||||
label: "settings.general.row.showCustomAgents.title",
|
||||
@@ -207,13 +214,6 @@ export const serverSettings: Entry<SettingsServerTab | "servers">[] = [
|
||||
description: "settings.general.row.shell.description",
|
||||
keywords: "bash zsh powershell",
|
||||
},
|
||||
{
|
||||
tab: "servers",
|
||||
label: "settings.server.preferences.websearch.title",
|
||||
target: "settings-websearch",
|
||||
description: "settings.server.preferences.websearch.description",
|
||||
keywords: "web search provider",
|
||||
},
|
||||
]
|
||||
|
||||
export const projectSettings: Entry<SettingsProjectTab>[] = [
|
||||
|
||||
@@ -19,12 +19,9 @@ import { SettingsSearchEmpty } from "./search-empty"
|
||||
export function SettingsSearch() {
|
||||
const language = useLanguage()
|
||||
const command = useCommand()
|
||||
const platform = usePlatform()
|
||||
const global = useGlobal()
|
||||
const servers = useSettingsServers()
|
||||
const surface = useSettingsSurface()
|
||||
const search = surface.search
|
||||
const mobile = createMediaQuery("(max-width: 767px)")
|
||||
const [state, setState] = createStore({ narrow: false, overflow: { start: false, end: false } })
|
||||
const listID = `settings-results-${createUniqueId()}`
|
||||
let root: HTMLDivElement | undefined
|
||||
@@ -62,29 +59,7 @@ export function SettingsSearch() {
|
||||
},
|
||||
])
|
||||
|
||||
const inventory = createMemo(() =>
|
||||
servers().map((server) => {
|
||||
const context = server.connection ? global.ensureServerCtx(server.connection) : undefined
|
||||
|
||||
return {
|
||||
...server,
|
||||
connected: context?.sdk.connection.status() === "connected",
|
||||
projects: context ? context.projects.list() : [],
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
const catalog = createMemo(() =>
|
||||
settingsSearchIndex({
|
||||
servers: inventory(),
|
||||
selected: surface.server()?.key,
|
||||
desktop: platform.platform === "desktop",
|
||||
browser: platform.platform === "desktop",
|
||||
mobile: mobile(),
|
||||
translate: language.t,
|
||||
extensions: surface.extensions.items(),
|
||||
}),
|
||||
)
|
||||
const catalog = createSettingsSearchCatalog()
|
||||
|
||||
const matches = createMemo(() => rankSettings(search.state.query, catalog()))
|
||||
|
||||
@@ -206,14 +181,11 @@ export function SettingsSearch() {
|
||||
search.expand()
|
||||
const index = shown().findIndex((item) => item.id === highlighted()?.id)
|
||||
|
||||
const next =
|
||||
shown()[
|
||||
event.key === "Home"
|
||||
? 0
|
||||
: event.key === "End"
|
||||
? shown().length - 1
|
||||
: Math.max(0, Math.min(shown().length - 1, index + (event.key === "ArrowDown" ? 1 : -1)))
|
||||
]
|
||||
const last = shown().length - 1
|
||||
const moves = { Home: 0, End: last, ArrowDown: Math.min(last, index + 1), ArrowUp: Math.max(0, index - 1) }
|
||||
const move = Object.entries(moves).find(([key]) => key === event.key)
|
||||
|
||||
const next = move && shown()[move[1]]
|
||||
|
||||
if (!next) return
|
||||
search.highlight(next.id)
|
||||
@@ -353,3 +325,37 @@ export function SettingsSearch() {
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** The settings search index for the current platform, servers, and extensions. */
|
||||
export function createSettingsSearchCatalog() {
|
||||
const language = useLanguage()
|
||||
const platform = usePlatform()
|
||||
const global = useGlobal()
|
||||
const servers = useSettingsServers()
|
||||
const surface = useSettingsSurface()
|
||||
const mobile = createMediaQuery("(max-width: 767px)")
|
||||
|
||||
const inventory = createMemo(() =>
|
||||
servers().map((server) => {
|
||||
const context = server.connection ? global.ensureServerCtx(server.connection) : undefined
|
||||
|
||||
return {
|
||||
...server,
|
||||
connected: context?.sdk.connection.status() === "connected",
|
||||
projects: context ? context.projects.list() : [],
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
return createMemo(() =>
|
||||
settingsSearchIndex({
|
||||
servers: inventory(),
|
||||
selected: surface.server()?.key,
|
||||
desktop: platform.platform === "desktop",
|
||||
browser: platform.platform === "desktop",
|
||||
mobile: mobile(),
|
||||
translate: language.t,
|
||||
extensions: surface.extensions.items(),
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -46,7 +46,15 @@ export const { use: useSettingsSurface, provider: SettingsSurfaceProvider } = cr
|
||||
|
||||
const extensions = createSettingsPages()
|
||||
const open = () => layout.route().type === "settings"
|
||||
const source = () => location.state?.settings?.route ?? { type: "home" as const }
|
||||
|
||||
// While Settings is closed, the current tab is where it would open from.
|
||||
const source = () => {
|
||||
const route = layout.route()
|
||||
|
||||
if (route.type !== "settings") return route
|
||||
|
||||
return location.state?.settings?.route ?? { type: "home" as const }
|
||||
}
|
||||
|
||||
const view = () => parseSettingsView(location.search, location.state?.settings?.view, extensions.tabs())
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ export function DialogCommandPalette(props: { onOpenFile?: (path: string) => voi
|
||||
return [
|
||||
...palette.commandEntries().filter((entry) => matchesCommandPaletteEntry(entry, q)),
|
||||
...palette.sessions.items(q),
|
||||
...palette.settings.items(q),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -237,7 +238,7 @@ function PaletteRow(props: {
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<Match when={props.item.type === "command"}>
|
||||
<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">{props.item.title}</span>
|
||||
|
||||
@@ -18,11 +18,13 @@ import { projectForSession } from "@/shell/layout/helpers"
|
||||
import { useExtensionHost } from "@/runtime/extension/host"
|
||||
import { useExtensionAttachment } from "@/runtime/extension/host-apis"
|
||||
import { looksLikeSessionID } from "@/session/search"
|
||||
import { createSettingsPaletteEntries } from "@/settings/palette"
|
||||
import type { SettingsSearchResult } from "@/settings/search-results"
|
||||
import { matchesCommandPaletteEntry } from "./search"
|
||||
|
||||
export type CommandPaletteEntry = {
|
||||
id: string
|
||||
type: "command" | "file" | "session"
|
||||
type: "command" | "file" | "session" | "setting"
|
||||
title: string
|
||||
description?: string
|
||||
keywords?: string
|
||||
@@ -36,6 +38,7 @@ export type CommandPaletteEntry = {
|
||||
project?: LocalProject
|
||||
archived?: number
|
||||
updated?: number
|
||||
setting?: SettingsSearchResult
|
||||
}
|
||||
|
||||
const ENTRY_LIMIT = 5
|
||||
@@ -90,6 +93,7 @@ export function createCommandPaletteModel(props: { filesOnly?: () => boolean; on
|
||||
const appTabs = useTabs()
|
||||
const extensions = useExtensionAttachment()
|
||||
const openFile = createCommandPaletteFileOpener(props.onOpenFile)
|
||||
const settings = createSettingsPaletteEntries()
|
||||
const state: PaletteHighlight = { cleanup: undefined, committed: false }
|
||||
const filesOnly = () => props.filesOnly?.() ?? false
|
||||
|
||||
@@ -191,6 +195,8 @@ export function createCommandPaletteModel(props: { filesOnly?: () => boolean; on
|
||||
return
|
||||
}
|
||||
|
||||
if (item.type === "setting") return settings.select(item)
|
||||
|
||||
if (!item.path) return
|
||||
openFile(item.path)
|
||||
}
|
||||
@@ -208,6 +214,7 @@ export function createCommandPaletteModel(props: { filesOnly?: () => boolean; on
|
||||
recentFileEntries,
|
||||
rootFileEntries,
|
||||
sessions,
|
||||
settings,
|
||||
highlight,
|
||||
select,
|
||||
close: () => dialog.close(),
|
||||
|
||||
@@ -91,7 +91,7 @@ export function createCommandPaletteSearch(props: {
|
||||
|
||||
if (!current) return entries
|
||||
|
||||
const order = { command: 0, session: 1, file: 2 }
|
||||
const order = { command: 0, session: 1, file: 2, setting: 3 }
|
||||
|
||||
return entries.toSorted(
|
||||
(a, b) =>
|
||||
|
||||
Reference in New Issue
Block a user