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 <noreply@anthropic.com>
This commit is contained in:
tao.chen
2026-07-23 19:36:29 +08:00
co-authored by Claude Fable 5
parent c0bcbda77f
commit 6ed267dcde
3 changed files with 37 additions and 0 deletions
@@ -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', () => {
+2
View File
@@ -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)}`
);
+9
View File
@@ -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