fix(app): tidy search shortcuts and add Unbind while recording (#58964)

Co-authored-by: vimtor <36263538+vimtor@users.noreply.github.com>
This commit is contained in:
opencode-agent[bot]
2026-10-25 12:01:54 +00:00
committed by GitHub
Unverified
parent 280c8e078a
commit 1f8a8bd133
17 changed files with 254 additions and 36 deletions
@@ -129,6 +129,43 @@ test("titlebar search lists recent sessions and opens the typed match", async ({
await expect(page.getByRole("heading", { name: paletteSession.title, exact: true })).toBeVisible()
})
test("Search commands lists only commands and runs the chosen one", async ({ page }) => {
const { dialog, input } = await openCommandPalette(page, true)
await input.fill("search commands")
await dialog.getByRole("option", { name: /^Search commands/ }).click()
const search = page.getByRole("dialog").getByRole("combobox")
await expect(search).toHaveAttribute("placeholder", "Search commands")
await expect(search).toBeFocused()
await expect(page.getByRole("dialog").getByRole("option", { name: /^Open settings/ })).toBeVisible()
await search.fill("Palette fixture")
await expect(page.getByRole("dialog").getByText("No results found", { exact: true })).toBeVisible()
await search.fill("open settings")
await expect(page.getByRole("dialog").getByRole("option")).toHaveCount(1)
await search.press("Enter")
await expect(page).toHaveURL("/settings")
})
test("Search projects opens a new session's project picker from a session and from Home", async ({ page }) => {
const editor = page.locator('[data-component="composer-editor"]')
const picker = page.getByRole("combobox", { name: "Search projects", exact: true })
const { dialog, input } = await openCommandPalette(page)
await input.fill("search projects")
await dialog.getByRole("option", { name: /^Search projects/ }).click()
await expect(page).toHaveURL(/\/new-session\?draftId=.+$/)
await expect(picker).toBeFocused()
await picker.press("Escape")
await expect(picker).toHaveCount(0)
await expect(editor).toBeFocused()
await page.goto("/")
await expect(
page.getByRole("region", { name: "Recent sessions" }).getByRole("button", { name: /Palette fixture session/ }),
).toBeEnabled()
await page.keyboard.press("ControlOrMeta+Shift+O")
await expect(page).toHaveURL(/\/new-session\?draftId=.+$/)
await expect(picker).toBeFocused()
})
test("reopens from its shortcut as soon as it closes", async ({ page }) => {
const { dialog, input } = await openCommandPalette(page)
await input.press("Escape")
@@ -210,11 +210,11 @@ test("Models and Shortcuts leave focus on navigation until the user types", asyn
}
const search = view.settings.getByRole("searchbox", { name: "Search shortcuts", exact: true })
await page.keyboard.press("p")
await page.keyboard.press("e")
await expect(search).toBeFocused()
await page.keyboard.type("alette")
await expect(search).toHaveValue("palette")
await expect(view.settings.getByText("Command palette", { exact: true })).toBeVisible()
await page.keyboard.type("verything")
await expect(search).toHaveValue("everything")
await expect(view.settings.getByText("Search everything", { exact: true })).toBeVisible()
})
test("section search takes typed input, clears in place, and escapes in steps", async ({ page }) => {
@@ -564,6 +564,28 @@ test("clearing project fields sends explicit removal values", async ({ page }) =
}
})
test("shortcuts list Search sessions once and unbind a shortcut while recording it", async ({ page }) => {
// Opening Settings from Home registers Home's Find, which must not add a second Search sessions.
const { settings } = await open(page)
await settings.getByRole("tab", { name: "Shortcuts", exact: true }).click()
await expect(settings.locator('[data-keybind-id="sessions.search"]')).toBeVisible()
await expect(settings.getByText("Search sessions", { exact: true })).toHaveCount(1)
const binding = settings.locator('[data-keybind-id="settings.open"]')
const unbind = settings.getByRole("button", { name: "Unbind", exact: true })
await expect(binding).toHaveText("Ctrl+,")
await expect(unbind).toHaveCount(0)
await binding.click()
await expect(binding).toHaveText("Press keys")
await unbind.click()
await expect(binding).toHaveText("Unassigned")
await expect(unbind).toHaveCount(0)
// An unassigned shortcut has nothing to unbind.
await binding.click()
await expect(binding).toHaveText("Press keys")
await expect(unbind).toHaveCount(0)
})
test("the new session shortcut waits for a shortcut recording, then leaves settings", async ({ page }) => {
const { settings } = await open(page)
await settings.getByRole("tab", { name: "Shortcuts", exact: true }).click()
+3 -2
View File
@@ -91,10 +91,11 @@ export function createHomeSessionSearchController(home: HomeController, sessions
if (layout.home.searchFocus.take()) focus()
})
// Home's Find focuses its session search, so Settings > Shortcuts lists one Find and one Search sessions.
command.register("home.search", () => [
{
id: "home.sessions.search.focus",
title: placeholder(),
id: "session.search",
title: language.t("session.search.placeholder"),
keybind: "mod+f",
hidden: true,
onSelect: focus,
+2 -2
View File
@@ -2,6 +2,7 @@ import { useDialog } from "@opencode/ui/context/dialog"
import { useSettingsCommand } from "@/settings/command"
import { useCommand } from "@/shell/commands/command"
import { useLanguage } from "@/runtime/i18n/language"
import { projectSearchCommand } from "@/shell/titlebar/titlebar"
export function useNewSessionCommands(input: {
restoreFocus: () => void
@@ -39,10 +40,9 @@ export function useNewSessionCommands(input: {
onSelect: input.restoreFocus,
},
{
id: "project.select",
...projectSearchCommand,
title: language.t("session.new.project.search"),
category: language.t("command.category.project"),
keybind: "mod+shift+o",
disabled: input.project.empty(),
onSelect: input.project.open,
},
+7 -1
View File
@@ -1,6 +1,7 @@
import { createPromptProjectController } from "@/new-session/project/selector"
import { useNewSessionLocationDialog } from "@/new-session/location/dialog"
import { useTabs, type DraftTab } from "@/shell/tabs/tabs"
import { useLayout } from "@/shell/state/layout"
import { useSearchParams } from "@solidjs/router"
import { createEffect, createMemo, createResource, on, untrack } from "solid-js"
import { createComposerModel } from "@/composer/model"
@@ -15,6 +16,7 @@ import { createDraftMcpControls } from "./mcp"
export default function NewSessionPage(props: { draftId: string }) {
const [search, setSearch] = useSearchParams<{ draftId?: string; prompt?: string }>()
const tabs = useTabs()
const layout = useLayout()
const draftTab = createMemo(() =>
tabs.store.find((tab): tab is DraftTab => tab.type === "draft" && tab.draftID === search.draftId),
@@ -62,7 +64,11 @@ export default function NewSessionPage(props: { draftId: string }) {
// a stale cursor a frame after every key-up and yank the caret from a key pressed in that frame.
createEffect(
on(composer.ready, (ready) => {
if (ready) model.restoreFocus()
if (!ready) return
// Search projects opened this draft; the picker returns focus to the composer when it closes.
if (layout.draft.projectSearch.take()) location()
else model.restoreFocus()
}),
)
createEffect(() => {
+3 -1
View File
@@ -66,7 +66,8 @@ export const dict = {
"command.usage.view.description": "See your OpenCode Go allowance and Console budgets",
"command.session.location.cycle": "Cycle session location",
"command.palette": "Command palette",
"command.palette": "Search everything",
"command.commands.search": "Search commands",
"command.session.new": "New session",
"command.session.search": "Search sessions",
@@ -1078,6 +1079,7 @@ export const dict = {
"settings.shortcuts.conflict.description": "{{keybind}} is already assigned to {{titles}}.",
"settings.shortcuts.unassigned": "Unassigned",
"settings.shortcuts.pressKeys": "Press keys",
"settings.shortcuts.unbind": "Unbind",
"settings.shortcuts.search.placeholder": "Search shortcuts",
"settings.shortcuts.group.general": "General",
+35 -16
View File
@@ -308,6 +308,11 @@ export function createKeybindSettingsController(
input.command.keybinds(false)
}
const unbind = (id: string) => {
input.settings.keybinds.set(id, "none")
stop()
}
const notify = input.notify ?? ((toast: { title: string; description: string }) => showToast(toast))
const handle = (event: KeyboardEvent) => {
@@ -333,8 +338,7 @@ export function createKeybindSettingsController(
!event.shiftKey
if (clear) {
input.settings.keybinds.set(id, "none")
stop()
unbind(id)
return
}
@@ -387,6 +391,7 @@ export function createKeybindSettingsController(
capture: {
active: () => store.active,
toggle,
unbind,
},
settings: {
hasOverrides: () => Object.values(overrides()).some((value) => typeof value === "string"),
@@ -420,6 +425,7 @@ export function SettingsKeybinds(props: { active?: boolean }) {
keybind={controller.catalog.keybind}
active={controller.capture.active()}
onCapture={controller.capture.toggle}
onUnbind={controller.capture.unbind}
hasOverrides={controller.settings.hasOverrides()}
onReset={controller.settings.reset}
/>
@@ -434,6 +440,7 @@ function SettingsKeybindsView(props: {
keybind: (id: string) => string
active: string | null
onCapture: (id: string) => void
onUnbind: (id: string) => void
hasOverrides: boolean
onReset: () => void
}) {
@@ -476,21 +483,33 @@ function SettingsKeybindsView(props: {
return (
<div class="flex items-center justify-between gap-4 py-3 border-b border-v2-border-border-base last:border-none">
<span>{props.title(id)}</span>
<Button
type="button"
size="small"
variant={binding() ? "ghost" : "ghost-muted"}
data-keybind-id={id}
data-expanded={props.active === id ? "" : undefined}
onClick={() => props.onCapture(id)}
>
<Show
when={props.active === id}
fallback={binding() || language.t("settings.shortcuts.unassigned")}
>
{language.t("settings.shortcuts.pressKeys")}
<div class="flex items-center gap-1">
<Show when={props.active === id && binding()}>
<Button
type="button"
size="small"
variant="ghost-danger"
onClick={() => props.onUnbind(id)}
>
{language.t("settings.shortcuts.unbind")}
</Button>
</Show>
</Button>
<Button
type="button"
size="small"
variant={binding() ? "ghost" : "ghost-muted"}
data-keybind-id={id}
data-expanded={props.active === id ? "" : undefined}
onClick={() => props.onCapture(id)}
>
<Show
when={props.active === id}
fallback={binding() || language.t("settings.shortcuts.unassigned")}
>
{language.t("settings.shortcuts.pressKeys")}
</Show>
</Button>
</div>
</div>
)
}}
@@ -3,10 +3,12 @@ import { Predicate } from "effect"
import type { useSettings } from "@/settings/model"
/**
* Stored custom keybinds of commands that built-in GUI extensions now publish under another id. Each old id maps to
* Stored custom keybinds of commands now published under another id, mostly by built-in GUI extensions. Each old id maps to
* the current one, and a newer old id comes first, so its override wins over an older one.
*/
export const keybindRenames = {
// Home's session search focus now follows Find; a custom binding of it keeps searching sessions.
"home.sessions.search.focus": "sessions.search",
"app.checkForUpdates": "updater.check",
"server.pair": "pairing.open",
"server.ssh.add": "ssh.add",
@@ -0,0 +1,51 @@
import { useDialog } from "@opencode/ui/context/dialog"
import { createMemo, onCleanup } from "solid-js"
import { useLanguage } from "@/runtime/i18n/language"
import { COMMAND_SEARCH_ID, commandPaletteOptions, useCommand } from "./command"
import { CommandPaletteView, matchesCommandPaletteEntry } from "./dialog"
import { createCommandPaletteCommandEntry, type CommandPaletteEntry, type PaletteHighlight } from "./palette"
/** Search everything, limited to commands. */
export function DialogCommandSearch() {
const command = useCommand()
const dialog = useDialog()
const language = useLanguage()
const state: PaletteHighlight = { cleanup: undefined, committed: false }
const entries = createMemo(() => {
const category = language.t("palette.group.commands")
return commandPaletteOptions(command.options)
.filter((option) => option.id !== COMMAND_SEARCH_ID)
.map((option) => createCommandPaletteCommandEntry(option, category))
})
const highlight = (item: CommandPaletteEntry | undefined) => {
state.cleanup?.()
state.cleanup = item?.option?.onHighlight?.()
}
const select = (item: CommandPaletteEntry | undefined) => {
if (!item) return
state.committed = true
state.cleanup = undefined
dialog.close()
void item.option?.onSelect?.("palette")
}
onCleanup(() => {
if (state.committed) return
state.cleanup?.()
})
return (
<CommandPaletteView
placeholder={language.t("command.commands.search")}
items={(query) => entries().filter((entry) => matchesCommandPaletteEntry(entry, query))}
sources={[]}
highlight={highlight}
select={select}
close={() => dialog.close()}
/>
)
}
@@ -15,6 +15,9 @@ const IS_MAC = /(Mac|iPod|iPhone|iPad)/.test(globalThis.navigator?.platform ?? "
const PALETTE_ID = "command.palette"
/** Search commands: Search everything (the palette) limited to commands. */
export const COMMAND_SEARCH_ID = "commands.search"
export const DEFAULT_PALETTE_KEYBIND = "mod+k,mod+shift+p"
const SUGGESTED_PREFIX = "suggested."
+12 -1
View File
@@ -12,7 +12,7 @@ import { useSettingsSurface } from "@/settings/surface"
import { useSettings } from "@/settings/model"
import { ExtensionServerCover } from "@/runtime/extension/server-shell"
import { ExtensionSlot } from "@/runtime/extension/render"
import { useCommand } from "@/shell/commands/command"
import { COMMAND_SEARCH_ID, useCommand } from "@/shell/commands/command"
import { useLanguage } from "@/runtime/i18n/language"
import { useGlobal } from "@/runtime/server/runtime"
import { useServers } from "@/runtime/server/registry"
@@ -193,6 +193,17 @@ export default function Layout(props: ParentProps) {
},
},
])
command.register("commands", () => [
{
id: COMMAND_SEARCH_ID,
title: language.t("command.commands.search"),
category: language.t("command.category.view"),
onSelect: async () => {
const { DialogCommandSearch } = await import("@/shell/commands/command-search")
void dialog.show(() => <DialogCommandSearch />)
},
},
])
const bottomTitlebar = () => mobile() && preferences.general.mobileTitlebarPosition() === "bottom"
const dragInset = () => windowDragEnabled(platform) && !mobile()
+16
View File
@@ -300,6 +300,9 @@ export const { use: useLayout, provider: LayoutProvider } = createSimpleContext(
// Opening Home with its shortcut focuses session search, so typing filters immediately.
let homeSearchFocus = false
// Search projects outside a draft opens a new draft, which then opens its project picker.
let draftProjectSearch = false
// Names of other session-scoped stores, e.g. extension storage, so pruning drops them with the layout state.
const [scoped, setScoped, , scopedReady] = persisted(
Persist.global("layout.scoped"),
@@ -453,6 +456,19 @@ export const { use: useLayout, provider: LayoutProvider } = createSimpleContext(
},
},
},
draft: {
projectSearch: {
request() {
draftProjectSearch = true
},
take() {
const requested = draftProjectSearch
draftProjectSearch = false
return requested
},
},
},
sessionState: {
/** Records a session-scoped store, so pruning a session's layout state drops it too. */
track(name: string) {
+22 -6
View File
@@ -37,6 +37,9 @@ import { TitlebarItems, useTitlebarItems } from "@/runtime/extension/titlebar-it
export const newTabCommand = { id: "tab.new", keybind: "mod+t,mod+n" }
/** A draft registers its own Search projects; everywhere else it opens a new draft with the project picker open. */
export const projectSearchCommand = { id: "project.select", keybind: "mod+shift+o" }
export const goBackCommand = { id: "common.goBack", keybind: "mod+[" }
export const goForwardCommand = { id: "common.goForward", keybind: "mod+]" }
@@ -338,6 +341,7 @@ export function Titlebar(props: { verticalTabs?: { mount?: HTMLElement } }) {
tabsStoreActions.removeSessions(detail)
})
/** Opens a new session draft for the current context. Returns false when there is nothing to open it in. */
const openNewTab = () => {
const route = layout.route()
@@ -349,12 +353,12 @@ export function Titlebar(props: { verticalTabs?: { mount?: HTMLElement } }) {
const model = tabs.stateValue<ComposerState>(pending.draft, "prompt")?.model.current()
void tabs.newDraft({ server: route.server, directory: pending.draft.directory }, "", model)
return
return true
}
const activeSession = session()
if (!activeSession) return
if (!activeSession) return false
const sessionTab = {
type: "session" as const,
@@ -369,18 +373,18 @@ export function Titlebar(props: { verticalTabs?: { mount?: HTMLElement } }) {
model,
)
return
return true
}
case "draft": {
const activeTab = currentTab()
if (activeTab?.type !== "draft") return
if (activeTab?.type !== "draft") return false
const model = tabs.stateValue<ComposerState>(activeTab, "prompt")?.model.current()
void tabs.newDraft({ server: activeTab.server, directory: activeTab.directory }, "", model)
return
return true
}
case "settings":
@@ -403,8 +407,10 @@ export function Titlebar(props: { verticalTabs?: { mount?: HTMLElement } }) {
if (conn && project) {
void tabs.newDraft({ server: ServerConnection.key(conn), directory: project.worktree }, "")
return
return true
}
return false
}
}
}
@@ -550,6 +556,16 @@ export function Titlebar(props: { verticalTabs?: { mount?: HTMLElement } }) {
tabsStoreActions.closeTab(tabsStore.findIndex((tab) => current === tab))
},
},
{
...projectSearchCommand,
title: language.t("session.new.project.search"),
category: language.t("command.category.project"),
onSelect: () => {
layout.draft.projectSearch.request()
if (!openNewTab()) layout.draft.projectSearch.take()
},
},
{
id: "tab.reopenClosed",
category: language.t("command.category.file"),
+19
View File
@@ -282,6 +282,25 @@
cursor: not-allowed;
}
/* Ghost danger: a destructive action that sits beside other ghost buttons */
[data-component="button-v2"][data-variant="ghost-danger"] {
background-color: transparent;
color: var(--v2-state-fg-danger);
}
[data-component="button-v2"][data-variant="ghost-danger"]:is(:hover, [data-state="hover"]):not(:disabled) {
background-color: var(--v2-overlay-simple-overlay-hover);
}
[data-component="button-v2"][data-variant="ghost-danger"]:is(:active, [data-state="pressed"]):not(:disabled) {
background-color: var(--v2-overlay-simple-overlay-pressed);
}
[data-component="button-v2"][data-variant="ghost-danger"]:is(:disabled, [data-state="disabled"]) {
opacity: 0.5;
cursor: not-allowed;
}
/* Ghost faint */
[data-component="button-v2"][data-variant="ghost-faint"] {
background-color: transparent;
@@ -5,7 +5,7 @@ const docs = `### Overview
Button v2 with visual variants and three sizes.
### API
- \`variant\`: "neutral" | "danger" | "warning" | "contrast" | "submit" | "ghost" | "ghost-muted" | "ghost-faint" | "loading".
- \`variant\`: "neutral" | "danger" | "warning" | "contrast" | "submit" | "ghost" | "ghost-muted" | "ghost-faint" | "ghost-danger" | "loading".
- \`submit\` shares the brighter contrast icon-button styling for Composer submission actions.
- \`size\`: "small" | "normal" | "large".
- \`icon\`: Optional icon name.
@@ -41,7 +41,18 @@ export default {
},
variant: {
control: "select",
options: ["neutral", "danger", "warning", "contrast", "submit", "ghost", "ghost-muted", "ghost-faint", "loading"],
options: [
"neutral",
"danger",
"warning",
"contrast",
"submit",
"ghost",
"ghost-muted",
"ghost-faint",
"ghost-danger",
"loading",
],
},
size: {
control: "select",
@@ -74,6 +85,7 @@ export const Variants = {
<Button variant="ghost-faint" icon="edit">
Ghost faint
</Button>
<Button variant="ghost-danger">Ghost danger</Button>
<Button variant="loading">Loading</Button>
</div>
),
@@ -17,6 +17,7 @@ export interface ButtonProps
| "ghost"
| "ghost-muted"
| "ghost-faint"
| "ghost-danger"
| "loading"
icon?: IconProps["name"]
}