mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 13:05:14 +03:00
feat(app): add worktree picker shortcuts and toggle shell mode (#60713)
This commit is contained in:
committed by
GitHub
Unverified
parent
1a443ae42a
commit
171dbd6abe
@@ -1011,6 +1011,7 @@
|
||||
"patchedDependencies": {
|
||||
"@ai-sdk/openai-compatible@2.0.41": "patches/@ai-sdk%2Fopenai-compatible@2.0.41.patch",
|
||||
"@tanstack/virtual-core@3.17.8": "patches/@tanstack%2Fvirtual-core@3.17.8.patch",
|
||||
"@brendonovich/vite-plugin-opencode@0.1.3": "patches/@brendonovich%2Fvite-plugin-opencode@0.1.3.patch",
|
||||
"electron-updater@6.8.9": "patches/electron-updater@6.8.9.patch",
|
||||
"pacote@21.5.1": "patches/pacote@21.5.1.patch",
|
||||
"@npmcli/agent@4.0.2": "patches/@npmcli%2Fagent@4.0.2.patch",
|
||||
|
||||
+2
-1
@@ -180,6 +180,7 @@
|
||||
"@corvu/drawer@0.2.4": "patches/@corvu%2Fdrawer@0.2.4.patch",
|
||||
"app-builder-lib@26.15.7": "patches/app-builder-lib@26.15.7.patch",
|
||||
"electron-updater@6.8.9": "patches/electron-updater@6.8.9.patch",
|
||||
"@pierre/trees@1.0.0-beta.6": "patches/@pierre%2Ftrees@1.0.0-beta.6.patch"
|
||||
"@pierre/trees@1.0.0-beta.6": "patches/@pierre%2Ftrees@1.0.0-beta.6.patch",
|
||||
"@brendonovich/vite-plugin-opencode@0.1.3": "patches/@brendonovich%2Fvite-plugin-opencode@0.1.3.patch"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1133,6 +1133,39 @@ test("/reload reloads the server's configuration once and reports it", async ({
|
||||
|
||||
const followUp = "Add follow-up, / for commands, @ for context…"
|
||||
|
||||
test("the shell shortcut toggles modes and keeps explicit bindings", async ({ page }) => {
|
||||
const view = await openDraft(page, {
|
||||
name: "ShellToggle",
|
||||
seed: {
|
||||
settings: {
|
||||
keybinds: { "prompt.mode.shell": "mod+alt+s", "prompt.mode.normal": "mod+alt+e" },
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const modifier = await page.evaluate(() => (/Mac/i.test(navigator.platform) ? "Meta" : "Control"))
|
||||
|
||||
const exit = page.getByRole("button", { name: /^Exit/ })
|
||||
|
||||
await view.editor.fill("echo hello")
|
||||
await view.editor.press(`${modifier}+Shift+x`)
|
||||
await expect(exit).toBeVisible()
|
||||
await expect(view.editor).toHaveText("echo hello")
|
||||
await view.editor.press(`${modifier}+Shift+x`)
|
||||
await expect(exit).toHaveCount(0)
|
||||
await expect(view.editor).toHaveText("echo hello")
|
||||
await view.editor.press(`${modifier}+Shift+x`)
|
||||
await expect(exit).toBeVisible()
|
||||
await view.editor.press("Escape")
|
||||
await expect(exit).toHaveCount(0)
|
||||
await expect(view.editor).toBeFocused()
|
||||
await view.editor.press(`${modifier}+Alt+s`)
|
||||
await expect(exit).toBeVisible()
|
||||
await view.editor.press(`${modifier}+Alt+e`)
|
||||
await expect(exit).toHaveCount(0)
|
||||
await expect(view.editor).toHaveText("echo hello")
|
||||
})
|
||||
|
||||
for (const row of [
|
||||
{ state: "an idle", copy: "Ask anything, / for commands, @ for context…" },
|
||||
{ state: "a running", copy: followUp, sessionStatus: { ses_placeholder: { type: "running" } } },
|
||||
|
||||
@@ -58,7 +58,7 @@ test("the new session screen does not show session details", async ({ page }) =>
|
||||
await expect(page.getByRole("button", { name: "Session details", exact: true })).toHaveCount(0)
|
||||
})
|
||||
|
||||
test("the location shortcut keeps cycling after hovering its icon", async ({ page }) => {
|
||||
test("the location shortcuts choose worktrees from every state and keep cycling", async ({ page }) => {
|
||||
const existing = "C:/OpenCode/LocationShortcut/.worktrees/quiet-river"
|
||||
|
||||
const view = await openDraft(page, {
|
||||
@@ -67,27 +67,133 @@ test("the location shortcut keeps cycling after hovering its icon", async ({ pag
|
||||
})
|
||||
|
||||
const modifier = await page.evaluate(() => (/Mac/i.test(navigator.platform) ? "Meta" : "Control"))
|
||||
const path = page.locator('[data-slot="new-session-location-path"]')
|
||||
const icon = page.locator('[data-slot="new-session-location-icon"]')
|
||||
|
||||
// The worktree trigger already says Local, so the local path has no icon of its own.
|
||||
const path = page.locator('[data-slot="new-session-location-path"]')
|
||||
|
||||
const search = page.getByRole("combobox", { name: "Search worktrees", exact: true })
|
||||
|
||||
await expect(path).toHaveText(view.directory)
|
||||
await expect(icon).toHaveCount(0)
|
||||
await newSessionWorktree(page).click()
|
||||
await view.editor.press(`${modifier}+Alt+KeyO`)
|
||||
await expect(search).toBeFocused()
|
||||
await page.getByRole("option", { name: /^quiet-river / }).click()
|
||||
await expect(view.editor).toBeFocused()
|
||||
await expect(path).toHaveText(existing)
|
||||
await icon.hover()
|
||||
await expect(page.getByRole("tooltip")).toContainText("Toggle session location")
|
||||
await view.editor.press(`${modifier}+Alt+KeyL`)
|
||||
await expect(newSessionWorktree(page)).toHaveText("Local")
|
||||
await expect(icon).toHaveCount(0)
|
||||
await expect(view.editor).toBeFocused()
|
||||
await expect(page.locator('[data-slot="new-session-location-icon"]')).toHaveCount(0)
|
||||
await view.editor.press(`${modifier}+Alt+KeyO`)
|
||||
await expect(search).toBeFocused()
|
||||
await page.getByRole("option", { name: /LocationShortcut C:\/OpenCode\/LocationShortcut$/ }).click()
|
||||
await view.editor.press(`${modifier}+Alt+KeyL`)
|
||||
await expect(newSessionWorktree(page)).toContainText("New worktree")
|
||||
await view.editor.press(`${modifier}+Alt+KeyO`)
|
||||
await expect(search).toBeFocused()
|
||||
await page.getByRole("option", { name: /^quiet-river / }).click()
|
||||
await expect(path).toHaveText(existing)
|
||||
await expect(view.editor).toBeFocused()
|
||||
})
|
||||
|
||||
for (const binding of ["custom", "none"]) {
|
||||
test(`the picker tooltips reflect ${binding} shortcuts`, async ({ page }) => {
|
||||
const view = await openDraft(page, {
|
||||
name: "PickerShortcuts",
|
||||
seed: {
|
||||
settings: {
|
||||
keybinds: {
|
||||
"project.select": binding === "custom" ? "mod+alt+p" : "none",
|
||||
"session.location.select": binding === "custom" ? "mod+alt+x" : "none",
|
||||
"session.location.cycle": binding === "custom" ? "mod+alt+k" : "none",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const tooltip = page.getByRole("tooltip").and(page.locator("[data-expanded]"))
|
||||
|
||||
const keys = tooltip.locator('[data-component="keybind-v2"]')
|
||||
|
||||
await newSessionLocation(page).hover()
|
||||
await expect(tooltip).toContainText("Choose project")
|
||||
|
||||
await expect(keys).toHaveText(binding === "custom" ? [/P$/] : [])
|
||||
await newSessionWorktree(page).hover()
|
||||
await expect(tooltip).toContainText("Isolate sessions with worktrees")
|
||||
|
||||
await expect(keys).toHaveText(binding === "custom" ? [/X$/] : [])
|
||||
|
||||
const modifier = await page.evaluate(() => (/Mac/i.test(navigator.platform) ? "Meta" : "Control"))
|
||||
|
||||
if (binding === "none") {
|
||||
await view.editor.press(`${modifier}+Alt+o`)
|
||||
await expect(page.getByRole("dialog")).toHaveCount(0)
|
||||
await expect(newSessionWorktree(page)).toHaveText("Local")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
await view.editor.press(`${modifier}+Alt+k`)
|
||||
await expect(newSessionWorktree(page)).toContainText("New worktree")
|
||||
await view.editor.press(`${modifier}+Alt+x`)
|
||||
const search = page.getByRole("combobox", { name: "Search worktrees", exact: true })
|
||||
|
||||
await expect(search).toBeFocused()
|
||||
await search.press("Escape")
|
||||
await expect(page.getByRole("dialog")).toHaveCount(0)
|
||||
await expect(newSessionWorktree(page)).toContainText("New worktree")
|
||||
await expect(view.editor).toBeFocused()
|
||||
await view.editor.press(`${modifier}+Alt+p`)
|
||||
await expect(page.getByRole("combobox", { name: "Search projects", exact: true })).toBeFocused()
|
||||
})
|
||||
}
|
||||
|
||||
test("the worktree picker shortcut is disabled for non-Git projects", async ({ page }) => {
|
||||
const view = await openDraft(page, { name: "NoWorktrees", project: { vcs: undefined } })
|
||||
|
||||
const modifier = await page.evaluate(() => (/Mac/i.test(navigator.platform) ? "Meta" : "Control"))
|
||||
|
||||
await expect(newSessionWorktree(page)).toHaveCount(0)
|
||||
await view.editor.press(`${modifier}+Alt+o`)
|
||||
await expect(page.getByRole("dialog")).toHaveCount(0)
|
||||
await view.editor.fill("Keep working locally")
|
||||
await expect(view.editor).toHaveText("Keep working locally")
|
||||
})
|
||||
|
||||
test("picker scrollbars overlay full-width rows and support dragging", async ({ page }) => {
|
||||
const root = "C:/OpenCode/OverlayMenus"
|
||||
|
||||
await openDraft(page, {
|
||||
name: "OverlayMenus",
|
||||
worktrees: () => [
|
||||
{ directory: root },
|
||||
...Array.from({ length: 24 }, (_, index) => ({
|
||||
directory: `${root}/worktree-${index}`,
|
||||
strategy: "git" as const,
|
||||
})),
|
||||
],
|
||||
})
|
||||
await newSessionWorktree(page).click()
|
||||
await expect(page.getByRole("combobox", { name: "Search worktrees", exact: true })).toBeFocused()
|
||||
|
||||
const menu = page.locator('[data-component="menu-scroll"]')
|
||||
|
||||
const viewport = menu.locator('[data-slot="menu-scroll-viewport"]')
|
||||
|
||||
const thumb = menu.locator('[data-slot="menu-scroll-thumb"]')
|
||||
|
||||
await menu.hover()
|
||||
await expect(thumb).toHaveCSS("opacity", "1")
|
||||
await expect.poll(() => viewport.evaluate((el) => el.getBoundingClientRect().width - el.clientWidth)).toBe(0)
|
||||
|
||||
const track = (await menu.boundingBox())!
|
||||
|
||||
const handle = (await thumb.boundingBox())!
|
||||
|
||||
await thumb.hover()
|
||||
await page.mouse.down()
|
||||
await page.mouse.move(handle.x + handle.width / 2, track.y + track.height - 4)
|
||||
await page.mouse.up()
|
||||
await expect.poll(() => viewport.evaluate((el) => el.scrollTop > 0)).toBe(true)
|
||||
await expect(page.getByRole("option", { name: /^worktree-23 / })).toBeInViewport()
|
||||
})
|
||||
|
||||
for (const row of [
|
||||
{
|
||||
name: "POSIX",
|
||||
@@ -108,6 +214,21 @@ for (const row of [
|
||||
await expect.poll(() => path.evaluate((el) => el.scrollWidth <= el.clientWidth)).toBe(true)
|
||||
await path.hover()
|
||||
await expect(page.getByRole("tooltip")).toHaveText(row.directory)
|
||||
|
||||
if (row.name !== "POSIX") return
|
||||
await expect(path).toHaveCSS("user-select", "text")
|
||||
await path.click()
|
||||
await path.evaluate((element) => {
|
||||
const range = document.createRange()
|
||||
|
||||
range.selectNodeContents(element)
|
||||
window.getSelection()?.removeAllRanges()
|
||||
window.getSelection()?.addRange(range)
|
||||
})
|
||||
const modifier = await page.evaluate(() => (/Mac/i.test(navigator.platform) ? "Meta" : "Control"))
|
||||
|
||||
await page.keyboard.press(`${modifier}+c`)
|
||||
await expect.poll(() => page.evaluate(() => navigator.clipboard.readText())).toBe(row.directory)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -234,11 +355,7 @@ test("the worktree trigger opens the current project's worktree step", async ({
|
||||
await local.click()
|
||||
await expect(search).toBeFocused()
|
||||
await expect(back).toHaveText("Run session in")
|
||||
await expect(options.locator(".command-palette-title")).toHaveText([
|
||||
"BranchWorktrees",
|
||||
"New worktree",
|
||||
"quiet-river",
|
||||
])
|
||||
await expect(options.locator(".command-palette-title")).toHaveText(["BranchWorktrees", "New worktree", "quiet-river"])
|
||||
await expect(options.nth(0)).toHaveAttribute("aria-selected", "true")
|
||||
|
||||
// Stepping back lands on the projects step with the drilled project active, as after drilling in with →.
|
||||
@@ -247,15 +364,28 @@ test("the worktree trigger opens the current project's worktree step", async ({
|
||||
await expect(projects).toBeFocused()
|
||||
await expect(back).toHaveCount(0)
|
||||
await expect(options.filter({ hasText: "BranchWorktrees" })).toHaveAttribute("aria-selected", "true")
|
||||
await projects.press("ArrowRight")
|
||||
await expect(search).toBeFocused()
|
||||
await search.press("Escape")
|
||||
await expect(projects).toBeFocused()
|
||||
await projects.press("Escape")
|
||||
await expect(dialog).toHaveCount(0)
|
||||
await expect(view.editor).toBeFocused()
|
||||
|
||||
// Escape also steps back first, then closes.
|
||||
// A directly opened worktree picker closes on Escape without showing projects first.
|
||||
await local.focus()
|
||||
await page.keyboard.press("Enter")
|
||||
await expect(search).toBeFocused()
|
||||
await search.press("Escape")
|
||||
await expect(dialog).toHaveCount(0)
|
||||
await expect(view.editor).toBeFocused()
|
||||
|
||||
// Drilling in from the project picker still makes Escape step back.
|
||||
await newSessionLocation(page).click()
|
||||
await expect(projects).toBeFocused()
|
||||
await projects.press("ArrowRight")
|
||||
await expect(search).toBeFocused()
|
||||
await search.press("Escape")
|
||||
await expect(projects).toBeFocused()
|
||||
await projects.press("Escape")
|
||||
await expect(dialog).toHaveCount(0)
|
||||
@@ -277,7 +407,7 @@ test("the branch shortcut chooses a base branch and stays inactive on Local", as
|
||||
|
||||
const modifier = await page.evaluate(() => (/Mac/i.test(navigator.platform) ? "Meta" : "Control"))
|
||||
|
||||
const shortcut = `${modifier}+Alt+Period`
|
||||
const shortcut = `${modifier}+Alt+KeyB`
|
||||
|
||||
const base = page.getByRole("button", { name: "from dev", exact: true })
|
||||
|
||||
@@ -285,7 +415,7 @@ test("the branch shortcut chooses a base branch and stays inactive on Local", as
|
||||
|
||||
await base.hover()
|
||||
await expect(page.getByRole("tooltip")).toContainText("Choose base branch")
|
||||
await expect(page.getByRole("tooltip").locator('[data-component="keybind-v2"]')).toContainText(".")
|
||||
await expect(page.getByRole("tooltip").locator('[data-component="keybind-v2"]')).toContainText("B")
|
||||
await expect(view.editor).toBeFocused()
|
||||
await view.editor.press(shortcut)
|
||||
await expect(search).toBeFocused()
|
||||
|
||||
@@ -579,11 +579,18 @@ export function createComposerModel(adapter: ComposerAdapter, options?: { queue?
|
||||
disabled: controller.state.mode !== "normal",
|
||||
onSelect: () => controller.attach(),
|
||||
},
|
||||
{
|
||||
id: "prompt.mode.toggle",
|
||||
title: language.t("command.prompt.mode.toggle"),
|
||||
category: language.t("command.category.session"),
|
||||
keybind: "mod+shift+x",
|
||||
onSelect: () =>
|
||||
void controller.dispatch({ type: controller.state.mode === "normal" ? "mode.shell" : "mode.normal" }),
|
||||
},
|
||||
{
|
||||
id: "prompt.mode.shell",
|
||||
title: language.t("command.prompt.mode.shell"),
|
||||
category: language.t("command.category.session"),
|
||||
keybind: "mod+shift+x",
|
||||
disabled: controller.state.mode === "shell",
|
||||
onSelect: () => void controller.dispatch({ type: "mode.shell" }),
|
||||
},
|
||||
@@ -591,7 +598,6 @@ export function createComposerModel(adapter: ComposerAdapter, options?: { queue?
|
||||
id: "prompt.mode.normal",
|
||||
title: language.t("command.prompt.mode.normal"),
|
||||
category: language.t("command.category.session"),
|
||||
keybind: "mod+shift+e",
|
||||
disabled: controller.state.mode === "normal",
|
||||
onSelect: () => void controller.dispatch({ type: "mode.normal" }),
|
||||
},
|
||||
|
||||
@@ -111,10 +111,6 @@
|
||||
color: var(--v2-text-text-faint);
|
||||
}
|
||||
|
||||
.new-session-location-workspace .command-palette-row-icon {
|
||||
color: var(--v2-icon-icon-base);
|
||||
}
|
||||
|
||||
.new-session-location-workspace .command-palette-row-text > .command-palette-title {
|
||||
max-width: 60%;
|
||||
flex-shrink: 0;
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Dialog, DialogBody } from "@opencode/ui/dialog"
|
||||
import { useDialog } from "@opencode/ui/context/dialog"
|
||||
import { Icon } from "@opencode/ui/icon"
|
||||
import { Keybind } from "@opencode/ui/keybind"
|
||||
import { MenuScroll } from "@opencode/ui/menu-scroll"
|
||||
import {
|
||||
displayName,
|
||||
getProjectAvatarGenerated,
|
||||
@@ -77,6 +78,7 @@ function NewSessionLocationDialog(props: {
|
||||
|
||||
const [store, setStore] = createStore<{
|
||||
drilled?: PromptProject
|
||||
direct: boolean
|
||||
/** Picking the server to add a project to. */
|
||||
picking?: boolean
|
||||
/** Browsing server projects this client has not added. */
|
||||
@@ -88,6 +90,7 @@ function NewSessionLocationDialog(props: {
|
||||
query: "",
|
||||
others: false,
|
||||
drilled: props.drilled,
|
||||
direct: !!props.drilled,
|
||||
back: props.drilled ? { query: "", active: projectEntryID(props.drilled), others: false } : undefined,
|
||||
})
|
||||
|
||||
@@ -281,6 +284,7 @@ function NewSessionLocationDialog(props: {
|
||||
setStore({
|
||||
drilled: undefined,
|
||||
picking: undefined,
|
||||
direct: false,
|
||||
others: store.drilled || store.picking ? (store.back?.others ?? false) : false,
|
||||
query: store.drilled || store.picking ? (store.back?.query ?? "") : "",
|
||||
back: undefined,
|
||||
@@ -367,6 +371,14 @@ function NewSessionLocationDialog(props: {
|
||||
return
|
||||
}
|
||||
|
||||
if (event.key === "Escape" && store.direct && store.drilled) {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
dialog.close()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (
|
||||
(store.drilled || store.picking || store.others) &&
|
||||
((event.key === backward && atStart) || (event.key === "Backspace" && !target.value) || event.key === "Escape")
|
||||
@@ -405,7 +417,11 @@ function NewSessionLocationDialog(props: {
|
||||
/>
|
||||
</div>
|
||||
<div class="new-session-location-divider" aria-hidden="true" />
|
||||
<div class="command-palette-scroll" data-scrollable ref={(el) => (resultsRef = el)}>
|
||||
<MenuScroll
|
||||
class="min-h-0 flex-1"
|
||||
viewportClass="command-palette-scroll"
|
||||
viewportRef={(el) => (resultsRef = el)}
|
||||
>
|
||||
<div id={typeahead.listID} class="command-palette-results" role="listbox">
|
||||
<div class="command-palette-group">
|
||||
<Show when={title()}>
|
||||
@@ -563,7 +579,7 @@ function NewSessionLocationDialog(props: {
|
||||
</Show>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</MenuScroll>
|
||||
</DialogBody>
|
||||
</Dialog>
|
||||
)
|
||||
|
||||
@@ -294,6 +294,17 @@ function NewSessionLocation(props: {
|
||||
const command = useCommand()
|
||||
const [layout, setLayout] = createStore({ width: 0, font: "" })
|
||||
|
||||
command.register("new-session-worktree", () => [
|
||||
{
|
||||
id: "session.location.select",
|
||||
title: language.t("session.location.worktree"),
|
||||
category: language.t("command.category.workspace"),
|
||||
keybind: "mod+alt+o",
|
||||
disabled: !props.onWorktree,
|
||||
onSelect: props.onWorktree,
|
||||
},
|
||||
])
|
||||
|
||||
const worktree = () => {
|
||||
if (props.workspace === "main") return
|
||||
|
||||
@@ -317,7 +328,14 @@ function NewSessionLocation(props: {
|
||||
<Tooltip
|
||||
placement="top"
|
||||
openDelay={800}
|
||||
value={language.t("session.new.project.trigger.tooltip")}
|
||||
value={
|
||||
<span class="flex items-center gap-2">
|
||||
{language.t("session.new.project.trigger.tooltip")}
|
||||
<Show when={command.keybindParts("project.select").length}>
|
||||
<Keybind keys={command.keybindParts("project.select")} variant="neutral" />
|
||||
</Show>
|
||||
</span>
|
||||
}
|
||||
class="flex min-w-0"
|
||||
>
|
||||
<button
|
||||
@@ -347,8 +365,8 @@ function NewSessionLocation(props: {
|
||||
placement="top"
|
||||
openDelay={800}
|
||||
value={
|
||||
props.onboarding ? (
|
||||
<div class="flex flex-col gap-1 text-start">
|
||||
<div class="flex flex-col gap-1 text-start">
|
||||
<Show when={props.onboarding}>
|
||||
<div class="flex items-center gap-1.5 font-[530] text-v2-text-text-base">
|
||||
<Icon name="outline-worktree" size="small" class="shrink-0 text-v2-text-text-accent" />
|
||||
<span>{language.t("workspace.onboarding.title")}</span>
|
||||
@@ -356,10 +374,17 @@ function NewSessionLocation(props: {
|
||||
<span class="font-[440] text-v2-text-text-muted">
|
||||
{language.t("workspace.onboarding.description")}
|
||||
</span>
|
||||
</div>
|
||||
) : (
|
||||
language.t("session.location.worktree")
|
||||
)
|
||||
</Show>
|
||||
<span
|
||||
class="flex items-center justify-between gap-2"
|
||||
classList={{ "font-[440] text-v2-text-text-muted": props.onboarding }}
|
||||
>
|
||||
{language.t("session.location.worktree")}
|
||||
<Show when={command.keybindParts("session.location.select").length}>
|
||||
<Keybind keys={command.keybindParts("session.location.select")} variant="neutral" />
|
||||
</Show>
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
contentClass={props.onboarding ? "max-w-[280px]" : undefined}
|
||||
class="flex min-w-12 shrink-[1000]"
|
||||
@@ -377,7 +402,9 @@ function NewSessionLocation(props: {
|
||||
size="small"
|
||||
class="shrink-0 text-v2-icon-icon-muted"
|
||||
/>
|
||||
<span class="min-w-0 truncate">{worktree() ?? language.t("session.new.workspace.triggerLocal")}</span>
|
||||
<span class="min-w-0 truncate">
|
||||
{worktree() ?? language.t("session.new.workspace.triggerLocal")}
|
||||
</span>
|
||||
<Show when={props.onboarding}>
|
||||
<span
|
||||
data-slot="workspace-onboarding-dot"
|
||||
@@ -398,7 +425,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(50%, ${Math.ceil(fitted().minimum) + 26}px)` }}
|
||||
style={{ "min-width": `min(50%, ${Math.ceil(fitted().minimum) + 6}px)` }}
|
||||
>
|
||||
<Tooltip
|
||||
placement="top"
|
||||
@@ -409,39 +436,24 @@ function NewSessionLocation(props: {
|
||||
>
|
||||
<span
|
||||
ref={(row) =>
|
||||
createResizeObserver(row, () => {
|
||||
const icon = row.querySelector("[data-slot=new-session-location-icon]")
|
||||
const style = getComputedStyle(row)
|
||||
|
||||
createResizeObserver(row, () =>
|
||||
setLayout({
|
||||
width: row.clientWidth - (icon ? icon.clientWidth + parseFloat(style.columnGap) : 0),
|
||||
font: style.font,
|
||||
})
|
||||
})
|
||||
width: row.clientWidth,
|
||||
font: getComputedStyle(row).font,
|
||||
}),
|
||||
)
|
||||
}
|
||||
class="flex min-w-0 flex-1 items-center justify-end gap-1.5"
|
||||
class="flex min-w-0 flex-1 items-center justify-end"
|
||||
dir="ltr"
|
||||
>
|
||||
{/* The worktree trigger already says Local, so only a worktree marks its path. */}
|
||||
<Show when={worktree()}>
|
||||
<Tooltip
|
||||
placement="top"
|
||||
openDelay={800}
|
||||
value={
|
||||
<span class="flex items-center gap-2">
|
||||
{language.t("session.location.toggle")}
|
||||
<Keybind keys={command.keybindParts("session.location.cycle")} variant="neutral" />
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<span class="flex shrink-0" data-slot="new-session-location-icon">
|
||||
<Icon name="outline-worktree" size="small" class="text-v2-icon-icon-muted" />
|
||||
</span>
|
||||
</Tooltip>
|
||||
</Show>
|
||||
<span
|
||||
data-slot="new-session-location-path"
|
||||
class="min-w-0 overflow-hidden whitespace-nowrap text-v2-text-text-faint [direction:rtl] [text-align:end]"
|
||||
class="min-w-0 cursor-text select-text overflow-hidden whitespace-nowrap text-v2-text-text-faint [direction:rtl] [text-align:end]"
|
||||
onCopy={(event) => {
|
||||
if (!event.clipboardData || window.getSelection()?.toString() !== fitted().text) return
|
||||
event.clipboardData.setData("text/plain", directory)
|
||||
event.preventDefault()
|
||||
}}
|
||||
>
|
||||
<bdi dir="ltr">{fitted().text}</bdi>
|
||||
</span>
|
||||
|
||||
@@ -55,7 +55,7 @@ export function NewSessionBranch(props: { workspace: NewSessionWorkspaceControll
|
||||
id: "session.branch.choose",
|
||||
title: language.t("command.session.branch.choose"),
|
||||
category: language.t("command.category.workspace"),
|
||||
keybind: "mod+alt+.",
|
||||
keybind: "mod+alt+b",
|
||||
disabled: !creating() || !props.workspace.bar.branch(),
|
||||
onSelect: (source) => {
|
||||
changeOpen(source === "palette" || !state.open)
|
||||
@@ -126,7 +126,7 @@ export function NewSessionBranch(props: { workspace: NewSessionWorkspaceControll
|
||||
when={creating()}
|
||||
fallback={
|
||||
<div class="flex h-7 min-w-0 max-w-[220px] items-center gap-1.5 ps-1.5 pe-2 text-v2-text-text-faint">
|
||||
<Icon name="branch" size="small" class="shrink-0 text-v2-icon-icon-muted" />
|
||||
<Icon name="branch" size="normal" class="shrink-0 text-v2-icon-icon-muted" />
|
||||
<span ref={observe} dir="auto" class="min-w-0 truncate">
|
||||
{label()}
|
||||
</span>
|
||||
@@ -140,7 +140,7 @@ export function NewSessionBranch(props: { workspace: NewSessionWorkspaceControll
|
||||
aria-description={language.t("command.session.branch.choose")}
|
||||
class="flex h-7 min-w-0 max-w-[220px] items-center gap-1.5 rounded-sm px-1.5 text-v2-text-text-muted transition-colors hover:bg-v2-overlay-simple-overlay-hover hover:text-v2-text-text-base focus-visible:bg-v2-overlay-simple-overlay-hover focus-visible:text-v2-text-text-base focus-visible:outline-none data-[expanded]:bg-v2-overlay-simple-overlay-pressed data-[expanded]:text-v2-text-text-base"
|
||||
>
|
||||
<Icon name="branch-out" size="small" class="shrink-0 text-v2-icon-icon-muted" />
|
||||
<Icon name="branch-out" size="normal" class="shrink-0 text-v2-icon-icon-muted" />
|
||||
<span ref={observe} dir="auto" class="min-w-0 truncate">
|
||||
{label()}
|
||||
</span>
|
||||
|
||||
@@ -103,6 +103,7 @@ export const dict = {
|
||||
"command.model.variant.cycle.description": "Switch to the next model variant",
|
||||
"command.prompt.mode.shell": "Shell",
|
||||
"command.prompt.mode.normal": "Prompt",
|
||||
"command.prompt.mode.toggle": "Toggle shell mode",
|
||||
"command.permissions.autoaccept.enable": "Auto-accept permissions",
|
||||
"command.permissions.autoaccept.disable": "Stop auto-accepting permissions",
|
||||
"command.permissions.autoaccept.project": "Auto-accept permissions for this project",
|
||||
|
||||
@@ -9,6 +9,7 @@ const attribute = "data-opencode-picker-source"
|
||||
export function pickerPlugin() {
|
||||
const plugin = picker()
|
||||
const client = "/__vite_opencode_picker_client.js"
|
||||
|
||||
let workspaceRoot = ""
|
||||
|
||||
return {
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
[data-component="menu-scroll"] {
|
||||
position: relative;
|
||||
display: flex;
|
||||
min-height: 0;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
isolation: isolate;
|
||||
}
|
||||
|
||||
[data-slot="menu-scroll-viewport"] {
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
[data-slot="menu-scroll-thumb"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
[data-slot="menu-scroll-viewport"] {
|
||||
scrollbar-width: none;
|
||||
}
|
||||
|
||||
[data-slot="menu-scroll-viewport"]::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
[data-slot="menu-scroll-thumb"] {
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
inset-inline-end: 0;
|
||||
top: 0;
|
||||
display: block;
|
||||
width: 8px;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
touch-action: none;
|
||||
user-select: none;
|
||||
|
||||
&::after {
|
||||
position: absolute;
|
||||
inset: 0 2px;
|
||||
border-radius: 9999px;
|
||||
background: var(--v2-border-border-muted);
|
||||
content: "";
|
||||
}
|
||||
|
||||
&:hover::after,
|
||||
&[data-dragging]::after {
|
||||
background: var(--v2-border-border-strong);
|
||||
}
|
||||
}
|
||||
|
||||
[data-component="menu-scroll"]:hover > [data-slot="menu-scroll-thumb"],
|
||||
[data-slot="menu-scroll-thumb"][data-dragging] {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import { createResizeObserver } from "@solid-primitives/resize-observer"
|
||||
import { onMount, Show, splitProps, type ComponentProps } from "solid-js"
|
||||
import { createStore } from "solid-js/store"
|
||||
import "./menu-scroll.css"
|
||||
|
||||
export function MenuScroll(
|
||||
props: Omit<ComponentProps<"div">, "ref" | "onScroll"> & {
|
||||
viewportClass?: string
|
||||
viewportRef?: (element: HTMLDivElement) => void
|
||||
},
|
||||
) {
|
||||
const [local, rest] = splitProps(props, ["class", "children", "viewportClass", "viewportRef"])
|
||||
|
||||
const [state, setState] = createStore<{ size: number; start: number; overflow: boolean; grab?: number }>({
|
||||
size: 0,
|
||||
start: 4,
|
||||
overflow: false,
|
||||
})
|
||||
|
||||
let viewport!: HTMLDivElement
|
||||
|
||||
let content!: HTMLDivElement
|
||||
|
||||
const measure = () => {
|
||||
const track = Math.max(0, viewport.clientHeight - 8)
|
||||
|
||||
const size = Math.min(track, Math.max(32, (viewport.clientHeight / Math.max(1, viewport.scrollHeight)) * track))
|
||||
|
||||
const max = viewport.scrollHeight - viewport.clientHeight
|
||||
|
||||
setState({ size, start: 4 + (max > 0 ? (viewport.scrollTop / max) * (track - size) : 0), overflow: max > 0 })
|
||||
|
||||
if (max <= 0) setState("grab", undefined)
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
local.viewportRef?.(viewport)
|
||||
createResizeObserver([viewport, content], measure)
|
||||
})
|
||||
|
||||
return (
|
||||
<div data-component="menu-scroll" class={local.class}>
|
||||
<div
|
||||
{...rest}
|
||||
ref={viewport}
|
||||
data-slot="menu-scroll-viewport"
|
||||
data-scrollable
|
||||
class={local.viewportClass}
|
||||
onScroll={measure}
|
||||
>
|
||||
<div ref={content}>{local.children}</div>
|
||||
</div>
|
||||
<Show when={state.overflow}>
|
||||
<div
|
||||
data-slot="menu-scroll-thumb"
|
||||
data-dragging={state.grab !== undefined ? "" : undefined}
|
||||
aria-hidden="true"
|
||||
style={{ height: `${state.size}px`, transform: `translateY(${state.start}px)` }}
|
||||
onPointerDown={(event) => {
|
||||
if (event.button !== 0) return
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
setState("grab", event.clientY - event.currentTarget.getBoundingClientRect().top)
|
||||
event.currentTarget.setPointerCapture(event.pointerId)
|
||||
}}
|
||||
onPointerMove={(event) => {
|
||||
if (state.grab === undefined) return
|
||||
const travel = viewport.clientHeight - 8 - state.size
|
||||
|
||||
if (travel <= 0) return
|
||||
viewport.scrollTop =
|
||||
((event.clientY - viewport.getBoundingClientRect().top - 4 - state.grab) / travel) *
|
||||
(viewport.scrollHeight - viewport.clientHeight)
|
||||
}}
|
||||
onPointerUp={(event) => {
|
||||
if (state.grab === undefined) return
|
||||
event.currentTarget.releasePointerCapture(event.pointerId)
|
||||
}}
|
||||
onLostPointerCapture={() => setState("grab", undefined)}
|
||||
/>
|
||||
</Show>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { Icon } from "@opencode/ui/icon"
|
||||
import { abort } from "@opencode/util/abort"
|
||||
import { useI18n } from "../../context/i18n"
|
||||
import { Loader } from "../../feedback/loader/loader"
|
||||
import { MenuScroll } from "../../components/menu-scroll"
|
||||
import { createTypeahead } from "./controller"
|
||||
|
||||
export { createTypeahead } from "./controller"
|
||||
@@ -165,12 +166,12 @@ export function Typeahead<T>(props: {
|
||||
)
|
||||
}
|
||||
>
|
||||
{/* A stable gutter keeps rows from shifting when the list overflows; the end padding gives way to it. */}
|
||||
<div
|
||||
<MenuScroll
|
||||
id={typeahead.listID}
|
||||
role="listbox"
|
||||
data-scrollable
|
||||
class="max-h-56 overflow-y-auto py-1 ps-1 pe-[max(0px,calc(4px-var(--scrollbar-size,0px)))] [scrollbar-gutter:stable] empty:hidden"
|
||||
class="max-h-56"
|
||||
viewportClass="p-1"
|
||||
classList={{ hidden: results().items.length === 0 }}
|
||||
>
|
||||
<For each={results().items}>
|
||||
{(item) => (
|
||||
@@ -195,7 +196,7 @@ export function Typeahead<T>(props: {
|
||||
</div>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
</MenuScroll>
|
||||
{/* Stays mounted while a retry or a newer query is pending, so the list never collapses to nothing. */}
|
||||
<Show when={results().items.length === 0}>
|
||||
<div
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
diff --git a/dist/index.js b/dist/index.js
|
||||
index 0bf00fc8965a8255e47694b450163f9cf6616bd8..5a901d835c022175ae45c393b34b12caf0686aaa 100644
|
||||
--- a/dist/index.js
|
||||
+++ b/dist/index.js
|
||||
@@ -735,6 +735,7 @@ textarea.addEventListener("input", () => {
|
||||
textarea.style.height = Math.min(textarea.scrollHeight, 140) + "px";
|
||||
});
|
||||
window.addEventListener("keydown", (event) => {
|
||||
+ if (event.code === "KeyD" && !active && !event.composedPath().includes(host)) return;
|
||||
if (
|
||||
dialog.classList.contains("open") &&
|
||||
(event.metaKey || event.ctrlKey) &&
|
||||
Reference in New Issue
Block a user