mirror of
https://github.com/anomalyco/opencode.git
synced 2026-06-01 22:10:06 +02:00
fix(tui): handle events across workspaces (#30281)
This commit is contained in:
@@ -958,11 +958,13 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
|
||||
bindings: tuiConfig.keybinds.gather("app_exit", ["app.exit"]),
|
||||
}))
|
||||
|
||||
event.on(TuiEvent.CommandExecute.type, (evt) => {
|
||||
event.on(TuiEvent.CommandExecute.type, (evt, { workspace }) => {
|
||||
if (workspace !== project.workspace.current()) return
|
||||
keymap.dispatchCommand(evt.properties.command)
|
||||
})
|
||||
|
||||
event.on(TuiEvent.ToastShow.type, (evt) => {
|
||||
event.on(TuiEvent.ToastShow.type, (evt, { workspace }) => {
|
||||
if (workspace !== project.workspace.current()) return
|
||||
toast.show({
|
||||
title: evt.properties.title,
|
||||
message: evt.properties.message,
|
||||
@@ -971,7 +973,8 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
|
||||
})
|
||||
})
|
||||
|
||||
event.on(TuiEvent.SessionSelect.type, (evt) => {
|
||||
event.on(TuiEvent.SessionSelect.type, (evt, { workspace }) => {
|
||||
if (workspace !== project.workspace.current()) return
|
||||
route.navigate({
|
||||
type: "session",
|
||||
sessionID: evt.properties.sessionID,
|
||||
@@ -988,7 +991,8 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
|
||||
}
|
||||
})
|
||||
|
||||
event.on("session.error", (evt) => {
|
||||
event.on("session.error", (evt, { workspace }) => {
|
||||
if (workspace !== project.workspace.current()) return
|
||||
const error = evt.properties.error
|
||||
if (error && typeof error === "object" && error.name === "MessageAbortedError") return
|
||||
const message = errorMessage(error)
|
||||
|
||||
@@ -319,7 +319,8 @@ export function Prompt(props: PromptProps) {
|
||||
let promptPartTypeId = 0
|
||||
const event = useEvent()
|
||||
|
||||
event.on(TuiEvent.PromptAppend.type, (evt) => {
|
||||
event.on(TuiEvent.PromptAppend.type, (evt, { workspace }) => {
|
||||
if (workspace !== project.workspace.current()) return
|
||||
if (!input || input.isDestroyed) return
|
||||
input.insertText(evt.properties.text)
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Event } from "@opencode-ai/sdk/v2"
|
||||
import * as Log from "@opencode-ai/core/util/log"
|
||||
import { useProject } from "./project"
|
||||
import { useSDK } from "./sdk"
|
||||
|
||||
@@ -16,9 +17,7 @@ export function useEvent() {
|
||||
return
|
||||
}
|
||||
|
||||
if (event.directory === "global" || event.project === project.project()) {
|
||||
handler(event.payload, { workspace: event.workspace })
|
||||
}
|
||||
handler(event.payload, { workspace: event.workspace })
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -113,19 +113,6 @@ describe("useEvent", () => {
|
||||
}
|
||||
})
|
||||
|
||||
test("ignores events for other projects", async () => {
|
||||
const { app, emit, seen } = await mount()
|
||||
|
||||
try {
|
||||
emit(event(vcs("other"), { directory, project: "proj_other" }))
|
||||
await Bun.sleep(30)
|
||||
|
||||
expect(seen).toHaveLength(0)
|
||||
} finally {
|
||||
app.renderer.destroy()
|
||||
}
|
||||
})
|
||||
|
||||
test("delivers current project events regardless of active workspace", async () => {
|
||||
const { app, emit, project, seen } = await mount()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user