mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-31 16:21:50 +03:00
fix(tui): prevent transcript from stealing focus
This commit is contained in:
+6
-4
@@ -1674,21 +1674,23 @@ describe("NanobotTui layout", () => {
|
|||||||
expect(setup.renderer.getSelection()).toBeNull()
|
expect(setup.renderer.getSelection()).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
test("returns text input focus when other TUI content is clicked", async () => {
|
test("keeps text input focus when the focusable transcript is clicked", async () => {
|
||||||
setup = await createRenderer({ width: 72, height: 20, screenMode: "alternate-screen" })
|
setup = await createRenderer({ width: 72, height: 20, screenMode: "alternate-screen" })
|
||||||
const app = mount(setup)
|
const app = mount(setup)
|
||||||
const ui = app as unknown as {
|
const ui = app as unknown as {
|
||||||
composer: TextareaRenderable
|
composer: TextareaRenderable
|
||||||
status: TextRenderable
|
transcript: {
|
||||||
|
root: { x: number; y: number; focused: boolean }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
app.accept({ event: "delta", chat_id: "chat", text: "clickable answer" })
|
app.accept({ event: "delta", chat_id: "chat", text: "clickable answer" })
|
||||||
app.accept({ event: "stream_end", chat_id: "chat" })
|
app.accept({ event: "stream_end", chat_id: "chat" })
|
||||||
await setup.flush()
|
await setup.flush()
|
||||||
|
|
||||||
ui.composer.blur()
|
await setup.mockMouse.click(ui.transcript.root.x + 1, ui.transcript.root.y + 1)
|
||||||
await setup.mockMouse.click(ui.status.x, ui.status.y)
|
|
||||||
|
|
||||||
expect(ui.composer.focused).toBe(true)
|
expect(ui.composer.focused).toBe(true)
|
||||||
|
expect(ui.transcript.root.focused).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
test("animates one stable status line while the agent works", async () => {
|
test("animates one stable status line while the agent works", async () => {
|
||||||
|
|||||||
+7
-1
@@ -511,7 +511,13 @@ export class NanobotTui {
|
|||||||
backgroundColor: RGBA.defaultBackground(),
|
backgroundColor: RGBA.defaultBackground(),
|
||||||
onMouseDown: (event) => {
|
onMouseDown: (event) => {
|
||||||
if (event.button !== 0) return
|
if (event.button !== 0) return
|
||||||
if (!this.diffViewer.visible) this.composer.focus()
|
if (!this.diffViewer.visible) {
|
||||||
|
// OpenTUI applies automatic focus after mouse handlers run. Prevent
|
||||||
|
// a focusable transcript ancestor from stealing text focus back
|
||||||
|
// after the composer has been restored here.
|
||||||
|
event.preventDefault()
|
||||||
|
this.composer.focus()
|
||||||
|
}
|
||||||
// Runtime pickers are transient popovers. A primary click anywhere
|
// Runtime pickers are transient popovers. A primary click anywhere
|
||||||
// outside their trigger or body dismisses them; hide() restores the
|
// outside their trigger or body dismisses them; hide() restores the
|
||||||
// composer focus through the shared visibility callback.
|
// composer focus through the shared visibility callback.
|
||||||
|
|||||||
Reference in New Issue
Block a user