Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/renderer/src/screens/Chat/ChatInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,33 @@ describe("ChatInput — CJK IME Enter handling", () => {
expect(onSubmit).toHaveBeenCalledWith("안녕하세요", []);
});
});

describe("ChatInput — Enter shortcut variants", () => {
it("submits on plain Enter", () => {
const { onSubmit, textarea } = renderInput();
fireEvent.change(textarea, { target: { value: "hello" } });
fireEvent.keyDown(textarea, { key: "Enter" });
expect(onSubmit).toHaveBeenCalledWith("hello", []);
});

it("does not submit on Shift+Enter (newline)", () => {
const { onSubmit, textarea } = renderInput();
fireEvent.change(textarea, { target: { value: "hello" } });
fireEvent.keyDown(textarea, { key: "Enter", shiftKey: true });
expect(onSubmit).not.toHaveBeenCalled();
});
Comment on lines +81 to +86

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 A test for Shift+Ctrl+Enter is missing. With the new condition this combo now submits (because ctrlKey short-circuits !shiftKey), but the PR description says Shift+Enter should always produce a newline. Adding this case would immediately surface the regression.

Suggested change
it("does not submit on Shift+Enter (newline)", () => {
const { onSubmit, textarea } = renderInput();
fireEvent.change(textarea, { target: { value: "hello" } });
fireEvent.keyDown(textarea, { key: "Enter", shiftKey: true });
expect(onSubmit).not.toHaveBeenCalled();
});
it("does not submit on Shift+Enter (newline)", () => {
const { onSubmit, textarea } = renderInput();
fireEvent.change(textarea, { target: { value: "hello" } });
fireEvent.keyDown(textarea, { key: "Enter", shiftKey: true });
expect(onSubmit).not.toHaveBeenCalled();
});
it("does not submit on Shift+Ctrl+Enter (newline takes precedence)", () => {
const { onSubmit, textarea } = renderInput();
fireEvent.change(textarea, { target: { value: "hello" } });
fireEvent.keyDown(textarea, { key: "Enter", shiftKey: true, ctrlKey: true });
expect(onSubmit).not.toHaveBeenCalled();
});

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


it("submits on Ctrl+Enter", () => {
const { onSubmit, textarea } = renderInput();
fireEvent.change(textarea, { target: { value: "hello" } });
fireEvent.keyDown(textarea, { key: "Enter", ctrlKey: true });
expect(onSubmit).toHaveBeenCalledWith("hello", []);
});

it("submits on Cmd+Enter (macOS)", () => {
const { onSubmit, textarea } = renderInput();
fireEvent.change(textarea, { target: { value: "hello" } });
fireEvent.keyDown(textarea, { key: "Enter", metaKey: true });
expect(onSubmit).toHaveBeenCalledWith("hello", []);
});
});
3 changes: 2 additions & 1 deletion src/renderer/src/screens/Chat/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
}
}

if (e.key === "Enter" && !e.shiftKey) {
// Send: plain Enter (without Shift) or Ctrl/Cmd+Enter
if (e.key === "Enter" && (!e.shiftKey || e.ctrlKey || e.metaKey)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Logic bug: Shift+Ctrl+Enter and Shift+Cmd+Enter now unexpectedly send

The new condition (!e.shiftKey || e.ctrlKey || e.metaKey) evaluates to true when ctrlKey or metaKey is set, regardless of shiftKey. So holding Shift+Ctrl+Enter (or Shift+Cmd+Enter) now submits the message instead of inserting a newline — contradicting the stated invariant that Shift always produces a newline.

Also note: the original !e.shiftKey condition already handled Ctrl+Enter and Cmd+Enter correctly (since those combos have shiftKey=false). The net observable change here is only for the Shift+modifier combinations, which aren't mentioned in the PR description or covered by the new tests.

A missing test case Shift+Ctrl+Enter (expecting onSubmit NOT to have been called) would surface this regression.

e.preventDefault();
handleSend();
}
Expand Down
Loading