Skip to content
Merged
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
18 changes: 18 additions & 0 deletions packages/app/src/components/AiAgentPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,24 @@ describe("AiAgentPanel", () => {
expect(submit).toHaveBeenCalledTimes(1);
});

it("does not send and keeps default newline behavior when Enter is pressed with Shift", () => {
const submit = vi.fn();
const updateDraft = vi.fn();

renderAgentPanel({
documentAvailable: true,
draft: "Summarize this note",
onDraftChange: updateDraft,
onSubmit: submit
});

const input = screen.getByRole("textbox", { name: "Markra AI message" });
const defaultAllowed = fireEvent.keyDown(input, { key: "Enter", shiftKey: true });

expect(defaultAllowed).toBe(true);
expect(submit).not.toHaveBeenCalled();
});

it("does not send when Enter confirms an IME composition", () => {
function Harness() {
const [draft, setDraft] = useState("Which AI models are available?");
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/components/AiAgentPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ export function AiAgentPanel({

const handleKeyDown = (event: ReactKeyboardEvent<HTMLTextAreaElement>) => {
if (event.key !== "Enter" || isComposingEnter(event)) return;
if (event.ctrlKey) return;
if (event.ctrlKey || event.shiftKey) return;

event.preventDefault();
submitComposer();
Expand Down
24 changes: 24 additions & 0 deletions packages/app/src/components/AiCommandBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,30 @@ describe("AiCommandBar", () => {
expect(onSubmit).not.toHaveBeenCalled();
});

it("inserts a newline with Shift+Enter", () => {
const onPromptChange = vi.fn();
const onSubmit = vi.fn();

render(
<AiCommandBar
language="en"
open
prompt="helloworld"
submitting={false}
onClose={vi.fn()}
onPromptChange={onPromptChange}
onSubmit={onSubmit}
/>
);

const input = screen.getByRole<HTMLTextAreaElement>("textbox", { name: "AI command" });
input.setSelectionRange(5, 5);
fireEvent.keyDown(input, { key: "Enter", shiftKey: true });

expect(onPromptChange).toHaveBeenCalledWith("hello\nworld");
expect(onSubmit).not.toHaveBeenCalled();
});

it("suggests the AI panel for structurally complex inline prompts", () => {
const onTransferToAiPanel = vi.fn();

Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/components/AiCommandBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ export function AiCommandBar({
if (event.key !== "Enter" || isComposingEnter(event)) return;

event.preventDefault();
if (event.ctrlKey) {
if (event.ctrlKey || event.shiftKey) {
insertPromptNewline(event.currentTarget);
return;
}
Expand Down
Loading