feat: Enter in the inline prompt textarea submits; Shift/Ctrl+Enter newline

Chat-input convention for the inline prompt's textarea:
  - Enter (no modifier): preventDefault() + click the send button
    (which validates non-empty text and calls onSubmit with the
    current text + the selected provider/model).
  - Shift+Enter / Ctrl+Enter: do NOT preventDefault, so the textarea
    inserts a newline (the default browser behavior).

Implementation:
  - opencode_inline_prompt.ts: add a keydown listener on the textarea
    in the constructor (right after the send button setup, so
    this._sendBtn is already assigned and the closure can call
    this._sendBtn.click()).

Tests:
  - 'Enter in the textarea submits; Shift+Enter does not':
    dispatches keydown Enter on the textarea and asserts the
    onSubmit jest.fn() is called once with the textarea value and the
    current provider/model. Then dispatches Shift+Enter and
    Ctrl+Enter and asserts onSubmit is NOT called.

Verification: pytest 37/37, jest 36/36 (was 35, +1).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
tao.chen
2026-07-23 19:39:54 +08:00
co-authored by Claude Fable 5
parent 6ed267dcde
commit a77c4c7ebe
2 changed files with 63 additions and 0 deletions
+8
View File
@@ -125,6 +125,14 @@ export class OpenCodeInlinePrompt extends Widget {
const modelId = this._modelSelect?.value || undefined;
options.onSubmit(text, providerId, modelId);
});
// Chat-input convention: Enter submits, Shift+Enter / Ctrl+Enter
// insert a newline (textarea default).
this._textarea.addEventListener('keydown', (e) => {
if (e.key === 'Enter' && !e.shiftKey && !e.ctrlKey) {
e.preventDefault();
this._sendBtn.click();
}
});
this._cancelBtn = document.createElement('button');
this._cancelBtn.className = 'opencode-btn-cancel';
this._cancelBtn.textContent = '取消';