From 6ed267dcde469868543efdc8fa07fe9a0fd27f6f Mon Sep 17 00:00:00 2001 From: "tao.chen" <93983997+taochen-ct@users.noreply.github.com> Date: Thu, 23 Jul 2026 19:36:29 +0800 Subject: [PATCH] feat: clear the inline prompt input textarea after a successful response After the user sends a message and the AI returns successfully, the inline prompt's textarea is cleared so they can immediately type a follow-up message without manually deleting the previous prompt. This is a re-add of the clearInput feature from the reverted fd30e53 commit, but WITHOUT the AI entry button position change (the button stays in the native cell toolbar per c0bcbda). Changes: - opencode_inline_prompt.ts: add clearInput() public method that sets this._textarea.value = ''. - opencode_cell_actions.ts: _handleResponse on a successful response calls this._prompt?.clearInput() after the history refresh, so the new conversation turn starts with a clean input. - test: 'clears the input textarea after a successful response' (types into the textarea, fires _handleResponse success, asserts textarea.value === ''). Verification: pytest 37/37, jest 35/35 (was 34, +1 new test). Co-Authored-By: Claude Fable 5 --- src/__tests__/opencode_cell_actions.spec.ts | 26 +++++++++++++++++++++ src/components/opencode_cell_actions.ts | 2 ++ src/components/opencode_inline_prompt.ts | 9 +++++++ 3 files changed, 37 insertions(+) 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