diff --git a/src/__tests__/opencode_cell_actions.spec.ts b/src/__tests__/opencode_cell_actions.spec.ts index 371c9db..b16d36e 100644 --- a/src/__tests__/opencode_cell_actions.spec.ts +++ b/src/__tests__/opencode_cell_actions.spec.ts @@ -422,6 +422,32 @@ describe('OpenCodeCellActions', () => { // A history refresh was triggered (to pick up the new assistant msg). expect(refreshSpy).toHaveBeenCalledWith('foo.ipynb'); }); + + it('clears the input textarea after a successful response', () => { + setOpenCodeProviders(null); + const cell = makeFakeCell('x = 1'); + const actions = new OpenCodeCellActions(cell); + Object.defineProperty(actions, 'parent', { value: cell, configurable: true }); + (actions as any).onAfterAttach({} as any); + + // Open the prompt and type something into the textarea. + const aiBtn = actions.node.querySelector('button') as HTMLButtonElement; + aiBtn.click(); + const prompt = (actions as any)._prompt; + expect(prompt).not.toBeNull(); + const textarea = prompt._textarea as HTMLTextAreaElement; + textarea.value = 'make it faster'; + + // A successful response clears the input so the user can type a + // follow-up message without manually deleting the previous prompt. + (actions as any)._handleResponse({ + ok: true, + markdown: 'ok', + sessionId: 'ses-1', + notebookPath: 'foo.ipynb' + }); + expect(textarea.value).toBe(''); + }); }); describe('OpenCodeInlinePrompt', () => { diff --git a/src/components/opencode_cell_actions.ts b/src/components/opencode_cell_actions.ts index d64bfaf..deea633 100644 --- a/src/components/opencode_cell_actions.ts +++ b/src/components/opencode_cell_actions.ts @@ -204,6 +204,8 @@ export class OpenCodeCellActions extends Widget { if (notebookPath) { void this._refreshHistory(notebookPath); } + // Clear the input so the user can type a follow-up message. + this._prompt?.clearInput(); Notification.info( `OpenCode 完成 (${resp.markdown.length} chars). Session: ${resp.sessionId.slice(0, 8)}…` ); diff --git a/src/components/opencode_inline_prompt.ts b/src/components/opencode_inline_prompt.ts index 9d692c8..a4fdc6c 100644 --- a/src/components/opencode_inline_prompt.ts +++ b/src/components/opencode_inline_prompt.ts @@ -211,6 +211,15 @@ export class OpenCodeInlinePrompt extends Widget { } } + /** + * Clear the user input textarea (called by the cell action after a + * successful response, so the user can type a follow-up message + * without manually deleting the previous prompt). + */ + clearInput(): void { + this._textarea.value = ''; + } + /** * Render the current session's messages into the scrollable history * area. User messages are plain text; assistant messages are rendered