Skip to content

Commit 45593b2

Browse files
committed
remove 'scope' parameter from commands
1 parent fe2a460 commit 45593b2

10 files changed

Lines changed: 29 additions & 34 deletions

File tree

packages/app/src/components/command-palette.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export function createCommandPaletteModel(props: { filesOnly?: () => boolean; on
9292

9393
const allowedCommands = createMemo(() => {
9494
if (filesOnly()) return []
95-
return commandPaletteOptions(command.options, "session")
95+
return commandPaletteOptions(command.options)
9696
})
9797
const commandEntries = createMemo(() => {
9898
const category = language.t("palette.group.commands")

packages/app/src/components/dialog-command-palette-v2.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function DialogHomeCommandPaletteV2(props: {
7373
const state = { cleanup: undefined as (() => void) | void, committed: false }
7474
const commandEntries = createMemo(() => {
7575
const category = language.t("palette.group.commands")
76-
return commandPaletteOptions(command.options, "general").map((option) =>
76+
return commandPaletteOptions(command.options).map((option) =>
7777
createCommandPaletteCommandEntry(option, category),
7878
)
7979
})

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,6 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
536536
{
537537
id: "file.attach",
538538
title: language.t("prompt.action.attachFile"),
539-
scope: "session",
540539
category: language.t("command.category.file"),
541540
keybind: "mod+u",
542541
disabled: store.mode !== "normal",
@@ -545,7 +544,6 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
545544
{
546545
id: "prompt.mode.shell",
547546
title: language.t("command.prompt.mode.shell"),
548-
scope: "session",
549547
category: language.t("command.category.session"),
550548
keybind: shellModeKey,
551549
disabled: store.mode === "shell",
@@ -554,7 +552,6 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
554552
{
555553
id: "prompt.mode.normal",
556554
title: language.t("command.prompt.mode.normal"),
557-
scope: "session",
558555
category: language.t("command.category.session"),
559556
keybind: normalModeKey,
560557
disabled: store.mode === "normal",

packages/app/src/context/command.test.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,15 @@ import { commandPaletteOptions, resolveKeybindOption, upsertCommandRegistration,
33

44
const paletteOptions: CommandOption[] = [
55
{ id: "settings.open", title: "Open settings" },
6-
{ id: "session.undo", title: "Undo", scope: "session" },
7-
{ id: "file.open", title: "Open file", scope: "session" },
6+
{ id: "session.undo", title: "Undo" },
7+
{ id: "file.open", title: "Open file" },
88
{ id: "hidden", title: "Hidden", hidden: true },
99
{ id: "disabled", title: "Disabled", disabled: true },
1010
]
1111

1212
describe("commandPaletteOptions", () => {
13-
test("keeps only general commands on home", () => {
14-
expect(commandPaletteOptions(paletteOptions, "general").map((option) => option.id)).toEqual(["settings.open"])
15-
})
16-
17-
test("keeps general and session commands in sessions", () => {
18-
expect(commandPaletteOptions(paletteOptions, "session").map((option) => option.id)).toEqual([
19-
"settings.open",
20-
"session.undo",
21-
])
13+
test("keeps visible enabled commands", () => {
14+
expect(commandPaletteOptions(paletteOptions).map((option) => option.id)).toEqual(["settings.open", "session.undo"])
2215
})
2316
})
2417

packages/app/src/context/command.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ export interface Keybind {
7575
export interface CommandOption {
7676
id: string
7777
title: string
78-
scope?: "general" | "session"
7978
description?: string
8079
category?: string
8180
keybind?: KeybindConfig
@@ -88,14 +87,13 @@ export interface CommandOption {
8887
onHighlight?: () => (() => void) | void
8988
}
9089

91-
export function commandPaletteOptions(options: CommandOption[], scope: "general" | "session") {
90+
export function commandPaletteOptions(options: CommandOption[]) {
9291
return options.filter(
9392
(option) =>
9493
!option.disabled &&
9594
!option.hidden &&
9695
!option.id.startsWith(SUGGESTED_PREFIX) &&
97-
option.id !== "file.open" &&
98-
(scope === "session" || option.scope !== "session"),
96+
option.id !== "file.open",
9997
)
10098
}
10199

packages/app/src/pages/layout.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -946,39 +946,34 @@ export default function LegacyLayout(props: ParentProps) {
946946
{
947947
id: "session.previous",
948948
title: language.t("command.session.previous"),
949-
scope: "session",
950949
category: language.t("command.category.session"),
951950
keybind: "alt+arrowup",
952951
onSelect: () => navigateSessionByOffset(-1),
953952
},
954953
{
955954
id: "session.next",
956955
title: language.t("command.session.next"),
957-
scope: "session",
958956
category: language.t("command.category.session"),
959957
keybind: "alt+arrowdown",
960958
onSelect: () => navigateSessionByOffset(1),
961959
},
962960
{
963961
id: "session.previous.unseen",
964962
title: language.t("command.session.previous.unseen"),
965-
scope: "session",
966963
category: language.t("command.category.session"),
967964
keybind: "shift+alt+arrowup",
968965
onSelect: () => navigateSessionByUnseen(-1),
969966
},
970967
{
971968
id: "session.next.unseen",
972969
title: language.t("command.session.next.unseen"),
973-
scope: "session",
974970
category: language.t("command.category.session"),
975971
keybind: "shift+alt+arrowdown",
976972
onSelect: () => navigateSessionByUnseen(1),
977973
},
978974
{
979975
id: "session.archive",
980976
title: language.t("command.session.archive"),
981-
scope: "session",
982977
category: language.t("command.category.session"),
983978
keybind: "mod+shift+backspace",
984979
disabled: !params.dir || !params.id,

packages/app/src/pages/new-session.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createStore } from "solid-js/store"
33
import { Portal } from "solid-js/web"
44
import { useSearchParams } from "@solidjs/router"
55
import { Tooltip } from "@opencode-ai/ui/tooltip"
6+
import { useDialog } from "@opencode-ai/ui/context/dialog"
67
import { Icon as IconV2 } from "@opencode-ai/ui/v2/icon"
78
import { TooltipV2 } from "@opencode-ai/ui/v2/tooltip-v2"
89
import { NewSessionDesignView } from "@/components/session"
@@ -51,6 +52,7 @@ export default function NewSessionPage() {
5152
const comments = useComments()
5253
const language = useLanguage()
5354
const settings = useSettings()
55+
const dialog = useDialog()
5456
const command = useCommand()
5557
const providers = useProviders(() => sdk().directory)
5658
const openProviderSettings = useSettingsDialog("providers")
@@ -76,10 +78,18 @@ export default function NewSessionPage() {
7678
})
7779

7880
command.register("new-session", () => [
81+
{
82+
id: "command.palette",
83+
title: language.t("command.palette"),
84+
hidden: true,
85+
onSelect: async () => {
86+
const { DialogSelectFile } = await import("@/components/dialog-select-file")
87+
void dialog.show(() => <DialogSelectFile />)
88+
},
89+
},
7990
{
8091
id: "input.focus",
8192
title: language.t("command.input.focus"),
82-
scope: "session",
8393
category: language.t("command.category.view"),
8494
keybind: "ctrl+l",
8595
onSelect: () => inputRef?.focus(),

packages/app/src/pages/session.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { useLocation, useNavigate, useParams, useSearchParams } from "@solidjs/r
4141
import { NewSessionView, SessionHeader } from "@/components/session"
4242
import { ErrorPage } from "@/pages/error"
4343
import { CommentsProvider, useComments } from "@/context/comments"
44+
import { useCommand } from "@/context/command"
4445
import { DirectoryDataProvider } from "@/pages/directory-layout"
4546
import { useServerSync } from "@/context/server-sync"
4647
import { useLanguage } from "@/context/language"
@@ -350,6 +351,7 @@ export default function Page() {
350351
const platform = usePlatform()
351352
const prompt = usePrompt()
352353
const comments = useComments()
354+
const command = useCommand()
353355
const terminal = useTerminal()
354356
const [searchParams, setSearchParams] = useSearchParams<{ prompt?: string }>()
355357
const location = useLocation()
@@ -1120,6 +1122,14 @@ export default function Page() {
11201122
review: reviewTab,
11211123
fileBrowser: () => newSessionDesign() && isDesktop() && !!params.id,
11221124
})
1125+
command.register("session-palette", () => [
1126+
{
1127+
id: "command.palette",
1128+
title: language.t("command.palette"),
1129+
hidden: true,
1130+
onSelect: () => command.trigger("file.open", "palette"),
1131+
},
1132+
])
11231133

11241134
const openReviewFile = createOpenReviewFile({
11251135
showAllFiles,

packages/app/src/pages/session/use-composer-commands.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const withCategory = (category: string) => {
1111
return (option: Omit<CommandOption, "category">): CommandOption => ({
1212
...option,
1313
category,
14-
scope: "session",
1514
})
1615
}
1716

packages/app/src/pages/session/use-session-commands.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const withCategory = (category: string) => {
3232
return (option: Omit<CommandOption, "category">): CommandOption => ({
3333
...option,
3434
category,
35-
scope: "session",
3635
})
3736
}
3837

@@ -464,12 +463,6 @@ export const useSessionCommands = (actions: SessionCommandContext) => {
464463
const fileCmds = () => {
465464
const tab = closableTab()
466465
return [
467-
fileCommand({
468-
id: "command.palette",
469-
title: language.t("command.palette"),
470-
hidden: true,
471-
onSelect: openFile,
472-
}),
473466
fileCommand({
474467
id: "file.open",
475468
title: language.t("command.file.open"),

0 commit comments

Comments
 (0)