Skip to content

Commit 498e9bf

Browse files
committed
fix(tui): close the line comment box when it loses focus
Moving focus elsewhere (a click on the composer or another pane) now dismisses the box without sending and leaves focus where it went. Also run the line comment tests in make tests.
1 parent d3aff00 commit 498e9bf

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

‎Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ BUN := mise exec -- bun
55
# Tests for changes made in this fork, relative to each package.
66
TUI_FORK_TESTS := test/ui/directory-link.test.ts test/ui/directory-markdown.test.tsx test/util/session.test.ts \
77
test/cli/tui/data.test.tsx test/cli/tui/dialog-open.test.tsx test/cli/tui/prompt-move.test.tsx test/config.test.tsx \
8-
test/context/session-tabs.test.tsx test/app-lifecycle.test.tsx test/component/session-tabs-rail.test.tsx
8+
test/context/session-tabs.test.tsx test/app-lifecycle.test.tsx test/component/session-tabs-rail.test.tsx \
9+
test/component/line-comment.test.tsx
910
CORE_FORK_TESTS := test/plugin/custom.test.ts test/plugin/supervisor.test.ts test/tool-cancel.test.ts \
1011
test/session-create.test.ts test/session-roots.test.ts test/session-skill.test.ts test/session-generate.test.ts \
1112
test/session-owned.test.ts test/session-runner.test.ts test/tool-skill.test.ts test/file-access.test.ts \

‎packages/tui/src/component/line-comment.tsx‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,21 @@ function LineCommentBox(props: {
9797
],
9898
}))
9999

100-
onMount(() => textarea()?.focus())
100+
// Focus moving elsewhere (a click on the composer or another pane) dismisses the box and leaves focus where it went.
101+
const state = { blurred: false }
102+
const dismiss = () => {
103+
state.blurred = true
104+
props.onCancel()
105+
}
106+
onMount(() => {
107+
const element = textarea()
108+
if (!element) return
109+
element.focus()
110+
element.on("blurred", dismiss)
111+
onCleanup(() => element.off("blurred", dismiss))
112+
})
101113
onCleanup(() => {
102-
if (previous && !previous.isDestroyed) previous.focus()
114+
if (!state.blurred && previous && !previous.isDestroyed) previous.focus()
103115
})
104116

105117
// The box floats inside a transcript row, whose clicks open message actions.

‎packages/tui/test/component/line-comment.test.tsx‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,24 @@ test("hovering a line shows a plus in its gutter, and the bar follows a drag up
111111
expect(setup.sent).toHaveLength(0)
112112
})
113113

114+
test("the comment box closes without sending when it loses focus", async () => {
115+
await using setup = await renderComment({ view: "unified", width: 80 })
116+
const app = setup.app
117+
const side = diffSides(app.renderer.root)[0]!
118+
const removed = rowOf(app, "const oldFirst")
119+
const original = background(app, removed)
120+
121+
await app.mockMouse.drag(side.x + 1, removed, side.x + 1, removed)
122+
await app.waitForFrame(() => app.renderer.currentFocusedRenderable instanceof TextareaRenderable)
123+
app.mockInput.typeText("Half")
124+
app.renderer.currentFocusedRenderable?.blur()
125+
await app.waitForFrame(
126+
(frame) =>
127+
!frame.includes("enter send") && background(app, removed) === original && marker(app, side, removed) === " ",
128+
)
129+
expect(setup.sent).toHaveLength(0)
130+
})
131+
114132
test("split line numbers comment on one side and cancelling sends nothing", async () => {
115133
await using setup = await renderComment({ view: "split", width: 160 })
116134
const app = setup.app

0 commit comments

Comments
 (0)