Skip to content
Draft
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
31 changes: 31 additions & 0 deletions src/components/InputBar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getAvailableSlashCommands,
getSlashCommandReplacement,
isClearCommandText,
shouldSubmitOnEnter,
} from "./input-bar";

describe("InputBar slash command helpers", () => {
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

The describe block name is now misleading: this suite includes shouldSubmitOnEnter behavior in addition to slash command helpers. Consider renaming the describe title or moving the Enter-related tests into a separate describe to keep test intent clear.

Copilot uses AI. Check for mistakes.
Expand Down Expand Up @@ -46,4 +47,34 @@ describe("InputBar slash command helpers", () => {
getSlashCommandReplacement({ name: "fix", description: "", source: "codex-skill", defaultPrompt: "bug" }),
).toBe("$fix bug");
});

it("does not submit enter while IME composition is active", () => {
expect(
shouldSubmitOnEnter({
key: "Enter",
shiftKey: false,
isComposing: true,
}),
).toBe(false);
expect(
shouldSubmitOnEnter({
key: "Enter",
shiftKey: false,
nativeEvent: { isComposing: true },
}),
).toBe(false);
expect(
shouldSubmitOnEnter({
key: "Enter",
shiftKey: false,
nativeEvent: { keyCode: 229 },
}),
).toBe(false);
});

it("submits enter only for non-composition send shortcut", () => {
expect(shouldSubmitOnEnter({ key: "Enter", shiftKey: false })).toBe(true);
expect(shouldSubmitOnEnter({ key: "Enter", shiftKey: true })).toBe(false);
expect(shouldSubmitOnEnter({ key: "a", shiftKey: false })).toBe(false);
});
});
3 changes: 2 additions & 1 deletion src/components/input-bar/InputBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
extractEditableContent,
getAvailableSlashCommands,
isClearCommandText,
shouldSubmitOnEnter,
} from "./input-bar-utils";
import { ContextGauge } from "./ContextGauge";
import { AttachmentPreview } from "./AttachmentPreview";
Expand Down Expand Up @@ -543,7 +544,7 @@ export const InputBar = memo(function InputBar({
return;
}

if (e.key === "Enter" && !e.shiftKey) {
if (shouldSubmitOnEnter(e)) {
e.preventDefault();
if (!isSending && !isAwaitingAcpOptions) {
handleSend();
Expand Down
1 change: 1 addition & 0 deletions src/components/input-bar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export {
getAvailableSlashCommands,
getSlashCommandReplacement,
isClearCommandText,
shouldSubmitOnEnter,
} from "./input-bar-utils";
21 changes: 21 additions & 0 deletions src/components/input-bar/input-bar-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,27 @@ export function fuzzyMatch(
return { match: false, score: 0 };
}

type EnterKeyEventLike = {
key: string;
shiftKey: boolean;
isComposing?: boolean;
nativeEvent?: {
isComposing?: boolean;
keyCode?: number;
};
};

/** Enter should submit only when not composing text via an IME. */
export function shouldSubmitOnEnter(event: EnterKeyEventLike): boolean {
if (event.key !== "Enter" || event.shiftKey) return false;
const nativeEvent = event.nativeEvent;
return !(
event.isComposing ||
nativeEvent?.isComposing ||
nativeEvent?.keyCode === 229
);
Comment on lines +160 to +167
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

nativeEvent?.keyCode === 229 introduces an unexplained magic number. Consider extracting 229 into a named constant (e.g. IME_PROCESS_KEYCODE) with a short comment about why it’s checked so future maintainers know what it represents.

Copilot uses AI. Check for mistakes.
}

// ── Slash command helpers (exported for tests + external consumers) ──

export const LOCAL_CLEAR_COMMAND: SlashCommand = {
Expand Down