Przeglądaj źródła

feat(tui): exit subagent menu with up arrow (#36951)

Co-authored-by: Aiden Cline <rekram1-node@users.noreply.github.com>
opencode-agent[bot] 1 miesiąc temu
rodzic
commit
888c4cb504

+ 6 - 0
packages/opencode/src/cli/cmd/run/footer.command.tsx

@@ -633,6 +633,12 @@ export function RunSubagentSelectBody(props: {
       return
     }
 
+    if (event.name.toLowerCase() === "up" && menu.selected() === 0) {
+      event.preventDefault()
+      props.onClose()
+      return
+    }
+
     handleKey({ event, menu, field: () => field, setQuery, select, close: props.onClose })
   })
 

+ 36 - 0
packages/opencode/test/cli/run/footer.view.test.tsx

@@ -642,6 +642,42 @@ test("direct subagent panel renders active subagents", async () => {
   }
 })
 
+test("direct subagent panel closes when moving up from the first item", async () => {
+  const [tabs] = createSignal([
+    subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow" }),
+    subagent({ sessionID: "s-2", label: "General", description: "Write migration plan" }),
+  ])
+  const [current] = createSignal<string | undefined>()
+  let closed = 0
+
+  const app = await testRender(
+    () => (
+      <box width={100} height={RUN_SUBAGENT_PANEL_ROWS}>
+        <RunSubagentSelectBody
+          theme={() => RUN_THEME_FALLBACK.footer}
+          tabs={tabs}
+          current={current}
+          onClose={() => closed++}
+          onSelect={() => {}}
+        />
+      </box>
+    ),
+    { width: 100, height: RUN_SUBAGENT_PANEL_ROWS },
+  )
+
+  try {
+    await app.renderOnce()
+    app.mockInput.pressKey("ARROW_DOWN")
+    app.mockInput.pressKey("ARROW_UP")
+    expect(closed).toBe(0)
+
+    app.mockInput.pressKey("ARROW_UP")
+    expect(closed).toBe(1)
+  } finally {
+    app.renderer.destroy()
+  }
+})
+
 test("direct queued prompt panel renders pending prompt actions", async () => {
   const [prompts] = createSignal([
     { messageID: "m-1", partID: "p-1", prompt: { text: "fix the auth test", parts: [] } },