fix(app): limit draft palette actions
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
This commit is contained in:
parent
14a5529793
commit
0c150f84f0
4 changed files with 33 additions and 4 deletions
|
|
@ -86,6 +86,7 @@ export function createCommandPaletteModel(props: { filesOnly?: () => boolean; on
|
|||
const openFile = createCommandPaletteFileOpener(props.onOpenFile)
|
||||
const state = { cleanup: undefined as (() => void) | void, committed: false }
|
||||
const filesOnly = () => props.filesOnly?.() ?? false
|
||||
const filesEnabled = () => filesOnly() || layout.route().type === "session"
|
||||
|
||||
const allowedCommands = createMemo(() => {
|
||||
if (filesOnly()) return []
|
||||
|
|
@ -114,6 +115,7 @@ export function createCommandPaletteModel(props: { filesOnly?: () => boolean; on
|
|||
normalizeTab: (tab) => (tab.startsWith("file://") ? file.tab(tab) : tab),
|
||||
})
|
||||
const recentFileEntries = createMemo(() => {
|
||||
if (!filesEnabled()) return []
|
||||
const all = tabState.openedTabs()
|
||||
const active = tabState.activeFileTab()
|
||||
const order = active ? [active, ...all.filter((item) => item !== active)] : all
|
||||
|
|
@ -130,6 +132,7 @@ export function createCommandPaletteModel(props: { filesOnly?: () => boolean; on
|
|||
.map((path) => createCommandPaletteFileEntry(path, category))
|
||||
})
|
||||
const rootFileEntries = createMemo(() => {
|
||||
if (!filesEnabled()) return []
|
||||
const category = language.t("palette.group.files")
|
||||
return file.tree
|
||||
.children("")
|
||||
|
|
@ -211,6 +214,7 @@ export function createCommandPaletteModel(props: { filesOnly?: () => boolean; on
|
|||
preferredCommandEntries,
|
||||
recentFileEntries,
|
||||
rootFileEntries,
|
||||
searchFiles: (query: string) => (filesEnabled() ? file.searchFiles(query) : Promise.resolve([])),
|
||||
sessions,
|
||||
highlight,
|
||||
select,
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ export function DialogCommandPaletteV2(props: { onOpenFile?: (path: string) => v
|
|||
const q = text.trim()
|
||||
if (!q) return [...palette.preferredCommandEntries(), ...palette.recentFileEntries()]
|
||||
|
||||
const [files, nextSessions] = await Promise.all([palette.file.searchFiles(q), Promise.resolve(palette.sessions(q))])
|
||||
const [files, nextSessions] = await Promise.all([palette.searchFiles(q), Promise.resolve(palette.sessions(q))])
|
||||
const category = palette.language.t("palette.group.files")
|
||||
return [
|
||||
...palette.commandEntries().filter((entry) => matchesEntry(entry, q)),
|
||||
|
|
|
|||
|
|
@ -92,13 +92,13 @@ function DialogSelectFileLegacy(props: { filesOnly: () => boolean; onOpenFile?:
|
|||
if (!query) return [...palette.preferredCommandEntries(), ...palette.recentFileEntries()]
|
||||
|
||||
if (props.filesOnly()) {
|
||||
const files = await palette.file.searchFiles(query)
|
||||
const files = await palette.searchFiles(query)
|
||||
const category = palette.language.t("palette.group.files")
|
||||
return files.map((path) => createCommandPaletteFileEntry(path, category))
|
||||
}
|
||||
|
||||
const [files, nextSessions] = await Promise.all([
|
||||
palette.file.searchFiles(query),
|
||||
palette.searchFiles(query),
|
||||
Promise.resolve(palette.sessions(query)),
|
||||
])
|
||||
const category = palette.language.t("palette.group.files")
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { Show, createEffect, createMemo, createResource, untrack } from "solid-js"
|
||||
import { Show, createEffect, createMemo, createResource, onCleanup, untrack } from "solid-js"
|
||||
import { createStore } from "solid-js/store"
|
||||
import { Portal } from "solid-js/web"
|
||||
import { useSearchParams } from "@solidjs/router"
|
||||
import { Tooltip } from "@opencode-ai/ui/tooltip"
|
||||
import { useDialog } from "@opencode-ai/ui/context/dialog"
|
||||
import { NewSessionDesignView } from "@/components/session"
|
||||
import { PromptInput } from "@/components/prompt-input"
|
||||
import { StatusPopoverV2 } from "@/components/status-popover"
|
||||
|
|
@ -19,6 +20,7 @@ import { useSync } from "@/context/sync"
|
|||
import { useServerSync } from "@/context/server-sync"
|
||||
import { useLanguage } from "@/context/language"
|
||||
import { useSettings } from "@/context/settings"
|
||||
import { useCommand } from "@/context/command"
|
||||
import { createPromptInputController, createPromptProjectControls } from "@/pages/session/composer"
|
||||
import { useSessionKey } from "@/pages/session/session-layout"
|
||||
import { useComposerCommands } from "@/pages/session/use-composer-commands"
|
||||
|
|
@ -41,11 +43,34 @@ export default function NewSessionPage() {
|
|||
const comments = useComments()
|
||||
const language = useLanguage()
|
||||
const settings = useSettings()
|
||||
const command = useCommand()
|
||||
const dialog = useDialog()
|
||||
const route = useSessionKey()
|
||||
const [searchParams, setSearchParams] = useSearchParams<{ draftId?: string; prompt?: string }>()
|
||||
|
||||
useComposerCommands()
|
||||
useSettingsCommand()
|
||||
let paletteRun = 0
|
||||
let paletteDead = false
|
||||
onCleanup(() => {
|
||||
paletteDead = true
|
||||
})
|
||||
command.register("draft-palette", () => [
|
||||
{
|
||||
id: "file.open",
|
||||
title: language.t("command.file.open"),
|
||||
description: language.t("palette.search.placeholder"),
|
||||
category: language.t("command.category.file"),
|
||||
keybind: "mod+k,mod+p",
|
||||
onSelect: () => {
|
||||
const run = ++paletteRun
|
||||
void import("@/components/dialog-select-file").then((module) => {
|
||||
if (paletteDead || run !== paletteRun) return
|
||||
dialog.show(() => <module.DialogSelectFile />)
|
||||
})
|
||||
},
|
||||
},
|
||||
])
|
||||
|
||||
let inputRef: HTMLDivElement | undefined
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue