Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(views): guard IME composition on Enter-to-submit handlers (#2207)

Naiyuan Qingdce51e3a27aa
diff --git a/packages/core/utils.test.ts b/packages/core/utils.test.ts
index e409b1d6f3..e4ad123742 100644
--- a/packages/core/utils.test.ts
+++ b/packages/core/utils.test.ts
@@ -1,5 +1,5 @@
import { afterEach, describe, expect, it, vi } from "vitest";
-import { createRequestId, createSafeId, generateUUID } from "./utils";
+import { createRequestId, createSafeId, generateUUID, isImeComposing } from "./utils";
afterEach(() => {
vi.unstubAllGlobals();
@@ -31,3 +31,25 @@ describe("utils id helpers", () => {
expect(createRequestId(12)).toBe("123456781234");
});
});
+
+describe("isImeComposing", () => {
+ it("returns true when nativeEvent.isComposing is set (React synthetic event)", () => {
+ expect(isImeComposing({ nativeEvent: { isComposing: true, keyCode: 13 } })).toBe(true);
+ });
+
+ it("returns true when nativeEvent.keyCode is 229 (Safari edge case)", () => {
+ // Safari clears isComposing on the keydown that ends composition; keyCode
+ // stays 229 throughout, which is the only reliable signal in that browser.
+ expect(isImeComposing({ nativeEvent: { isComposing: false, keyCode: 229 } })).toBe(true);
+ });
+
+ it("returns true for native KeyboardEvent without nativeEvent wrapper", () => {
+ expect(isImeComposing({ isComposing: true, keyCode: 13 })).toBe(true);
+ expect(isImeComposing({ isComposing: false, keyCode: 229 })).toBe(true);
+ });
+
+ it("returns false when not composing", () => {
+ expect(isImeComposing({ nativeEvent: { isComposing: false, keyCode: 13 } })).toBe(false);
+ expect(isImeComposing({ isComposing: false, keyCode: 13 })).toBe(false);
+ });
+});
diff --git a/packages/core/utils.ts b/packages/core/utils.ts
index 072812c0d6..4122bddabc 100644
--- a/packages/core/utils.ts
+++ b/packages/core/utils.ts
@@ -48,3 +48,28 @@ export function createSafeId(): string {
export function createRequestId(length = 8): string {
return createSafeId().replace(/-/g, "").slice(0, length);
}
+
+/**
+ * True when the keyboard event fires while an IME is composing a multi-key
+ * input (e.g. Chinese pinyin, Japanese kana). The Enter that commits the
+ * composition must NOT trigger submit/send/create handlers.
+ *
+ * Accepts both React synthetic events and native DOM `KeyboardEvent`s.
+ *
+ * Why both `isComposing` and `keyCode === 229`:
+ * - `isComposing` is the standard signal but Safari clears it on the keydown
+ * that ends composition, so a bare check misses the very Enter that submits.
+ * - During composition the browser reports `keyCode === 229` regardless of
+ * the actual key, which keeps working in Safari's edge case.
+ *
+ * Always read from `nativeEvent` when present — React's synthetic event is
+ * normalized but the native event reflects the browser's real state.
+ */
+export function isImeComposing(event: {
+ isComposing?: boolean;
+ keyCode?: number;
+ nativeEvent?: { isComposing?: boolean; keyCode?: number };
+}): boolean {
+ const e = event.nativeEvent ?? event;
+ return Boolean(e.isComposing) || e.keyCode === 229;
+}
diff --git a/packages/views/agents/components/agent-detail-inspector.tsx b/packages/views/agents/components/agent-detail-inspector.tsx
index 7979904880..61aea70b35 100644
--- a/packages/views/agents/components/agent-detail-inspector.tsx
+++ b/packages/views/agents/components/agent-detail-inspector.tsx
@@ -19,7 +19,7 @@ import {
} from "@multica/core/agents";
import { api } from "@multica/core/api";
import { useFileUpload } from "@multica/core/hooks/use-file-upload";
-import { timeAgo } from "@multica/core/utils";
+import { isImeComposing, timeAgo } from "@multica/core/utils";
import { Button } from "@multica/ui/components/ui/button";
import { ActorAvatar } from "../../common/actor-avatar";
import { Input } from "@multica/ui/components/ui/input";
@@ -455,7 +455,11 @@ function DescriptionEditorBody({
placeholder={t(($) => $.inspector.description_placeholder)}
rows={6}
onKeyDown={(e) => {
- if (e.key === "Escape") onClose();
+ if (e.key === "Escape") {
+ onClose();
+ return;
+ }
+ if (isImeComposing(e)) return;
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
e.preventDefault();
void commit();
@@ -561,11 +565,14 @@ function InlineEditPopover({
}}
placeholder={placeholder}
onKeyDown={(e) => {
+ if (e.key === "Escape") {
+ setOpen(false);
+ return;
+ }
+ if (isImeComposing(e)) return;
if (e.key === "Enter") {
e.preventDefault();
void commit();
- } else if (e.key === "Escape") {
- setOpen(false);
}
}}
className="h-8"
@@ -580,7 +587,11 @@ function InlineEditPopover({
}}
placeholder={placeholder}
onKeyDown={(e) => {
- if (e.key === "Escape") setOpen(false);
+ if (e.key === "Escape") {
+ setOpen(false);
+ return;
+ }
+ if (isImeComposing(e)) return;
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
e.preventDefault();
void commit();
diff --git a/packages/views/agents/components/create-agent-dialog.tsx b/packages/views/agents/components/create-agent-dialog.tsx
index 86c26a20f8..b16538a528 100644
--- a/packages/views/agents/components/create-agent-dialog.tsx
+++ b/packages/views/agents/components/create-agent-dialog.tsx
@@ -12,6 +12,7 @@ import type {
MemberWithUser,
CreateAgentRequest,
} from "@multica/core/types";
+import { isImeComposing } from "@multica/core/utils";
import {
Dialog,
DialogContent,
@@ -172,7 +173,10 @@ export function CreateAgentDialog({
onChange={(e) => setName(e.target.value)}
placeholder={t(($) => $.create_dialog.name_placeholder)}
className="mt-1"
- onKeyDown={(e) => e.key === "Enter" && handleSubmit()}
+ onKeyDown={(e) => {
+ if (isImeComposing(e)) return;
+ if (e.key === "Enter") handleSubmit();
+ }}
/>
</div>
diff --git a/packages/views/editor/extensions/mention-suggestion.tsx b/packages/views/editor/extensions/mention-suggestion.tsx
index fd11507198..4de74b38fa 100644
--- a/packages/views/editor/extensions/mention-suggestion.tsx
+++ b/packages/views/editor/extensions/mention-suggestion.tsx
@@ -18,6 +18,7 @@ import { workspaceKeys } from "@multica/core/workspace/queries";
import { useAuthStore } from "@multica/core/auth";
import { canAssignAgentToIssue } from "@multica/core/permissions";
import { api } from "@multica/core/api";
+import { isImeComposing } from "@multica/core/utils";
import type {
Issue,
ListIssuesCache,
@@ -204,6 +205,9 @@ export const MentionList = forwardRef<MentionListRef, MentionListProps>(
useImperativeHandle(ref, () => ({
onKeyDown: ({ event }) => {
+ // IME is composing — don't intercept Enter/Arrow as picker actions;
+ // those keys belong to the IME (Enter commits composition, etc).
+ if (isImeComposing(event)) return false;
if (event.key === "ArrowUp") {
if (displayItems.length === 0) return true;
setSelectedIndex(
diff --git a/packages/views/issues/components/labels-panel.tsx b/packages/views/issues/components/labels-panel.tsx
index 4daf5e0f38..dd3e982792 100644
--- a/packages/views/issues/components/labels-panel.tsx
+++ b/packages/views/issues/components/labels-panel.tsx
@@ -20,6 +20,7 @@ import { toast } from "sonner";
import { useWorkspaceId } from "@multica/core/hooks";
import { labelListOptions, useCreateLabel, useUpdateLabel, useDeleteLabel } from "@multica/core/labels";
import type { Label } from "@multica/core/types";
+import { isImeComposing } from "@multica/core/utils";
import { LabelChip } from "../../labels/label-chip";
import { useT } from "../../i18n";
@@ -116,6 +117,7 @@ export function LabelsPanel() {
value={newName}
onChange={(e) => setNewName(e.target.value)}
onKeyDown={(e) => {
+ if (isImeComposing(e)) return;
if (e.key === "Enter") handleCreate();
}}
className="flex-1"
@@ -152,8 +154,12 @@ export function LabelsPanel() {
if (e.target.value.trim()) setEditError("");
}}
onKeyDown={(e) => {
+ if (e.key === "Escape") {
+ cancelEdit();
+ return;
+ }
+ if (isImeComposing(e)) return;
if (e.key === "Enter") saveEdit(label.id);
- if (e.key === "Escape") cancelEdit();
}}
className="flex-1 h-8"
maxLength={32}
diff --git a/packages/views/issues/components/pickers/property-picker.tsx b/packages/views/issues/components/pickers/property-picker.tsx
index c27462c0c2..627adca6cc 100644
--- a/packages/views/issues/components/pickers/property-picker.tsx
+++ b/packages/views/issues/components/pickers/property-picker.tsx
@@ -12,6 +12,7 @@ import {
TooltipContent,
TooltipTrigger,
} from "@multica/ui/components/ui/tooltip";
+import { isImeComposing } from "@multica/core/utils";
import { useT } from "../../../i18n";
const HIGHLIGHT_CLASS = "bg-accent";
@@ -107,6 +108,9 @@ export function PropertyPicker({
const handleKeyDown = useCallback(
(e: React.KeyboardEvent) => {
+ // IME is composing — Enter/Arrow belong to the IME (Enter commits
+ // composition; Arrow rotates candidates). Don't hijack them.
+ if (isImeComposing(e)) return;
const items = getItems();
if (items.length === 0) return;
diff --git a/packages/views/onboarding/steps/step-workspace.tsx b/packages/views/onboarding/steps/step-workspace.tsx
index 250d882ca9..de7a2a3772 100644
--- a/packages/views/onboarding/steps/step-workspace.tsx
+++ b/packages/views/onboarding/steps/step-workspace.tsx
@@ -23,6 +23,7 @@ import { useScrollFade } from "@multica/ui/hooks/use-scroll-fade";
import { cn } from "@multica/ui/lib/utils";
import { useCreateWorkspace } from "@multica/core/workspace/mutations";
import type { Workspace } from "@multica/core/types";
+import { isImeComposing } from "@multica/core/utils";
import { DragStrip } from "@multica/views/platform";
import { StepHeader } from "../components/step-header";
import { RadioMark } from "../components/option-card";
@@ -201,7 +202,10 @@ export function StepWorkspace({
value={name}
onChange={(e) => handleNameChange(e.target.value)}
placeholder={t(($) => $.step_workspace.name_placeholder)}
- onKeyDown={(e) => e.key === "Enter" && handleCreate()}
+ onKeyDown={(e) => {
+ if (isImeComposing(e)) return;
+ if (e.key === "Enter") handleCreate();
+ }}
/>
</div>
<div className="flex flex-col gap-1.5">
@@ -222,7 +226,10 @@ export function StepWorkspace({
onChange={(e) => handleSlugChange(e.target.value)}
placeholder={t(($) => $.step_workspace.slug_placeholder)}
className="border-0 bg-transparent font-mono shadow-none focus-visible:ring-0"
- onKeyDown={(e) => e.key === "Enter" && handleCreate()}
+ onKeyDown={(e) => {
+ if (isImeComposing(e)) return;
+ if (e.key === "Enter") handleCreate();
+ }}
/>
</div>
{slugError && <p className="text-xs text-destructive">{slugError}</p>}
diff --git a/packages/views/settings/components/delete-workspace-dialog.tsx b/packages/views/settings/components/delete-workspace-dialog.tsx
index 32ebaf1d95..777e621eb8 100644
--- a/packages/views/settings/components/delete-workspace-dialog.tsx
+++ b/packages/views/settings/components/delete-workspace-dialog.tsx
@@ -12,6 +12,7 @@ import {
import { Input } from "@multica/ui/components/ui/input";
import { Label } from "@multica/ui/components/ui/label";
import { Button } from "@multica/ui/components/ui/button";
+import { isImeComposing } from "@multica/core/utils";
import { useT } from "../../i18n";
/**
@@ -83,6 +84,7 @@ export function DeleteWorkspaceDialog({
value={typed}
onChange={(e) => setTyped(e.target.value)}
onKeyDown={(e) => {
+ if (isImeComposing(e)) return;
if (e.key === "Enter") {
e.preventDefault();
submit();
diff --git a/packages/views/skills/components/create-skill-dialog.tsx b/packages/views/skills/components/create-skill-dialog.tsx
index 39846b82f0..2c99637255 100644
--- a/packages/views/skills/components/create-skill-dialog.tsx
+++ b/packages/views/skills/components/create-skill-dialog.tsx
@@ -17,6 +17,7 @@ import { useQueryClient } from "@tanstack/react-query";
import { api } from "@multica/core/api";
import type { Skill } from "@multica/core/types";
import { useWorkspaceId } from "@multica/core/hooks";
+import { isImeComposing } from "@multica/core/utils";
import {
skillDetailOptions,
workspaceKeys,
@@ -163,6 +164,7 @@ function ManualForm({
}}
placeholder={t(($) => $.create.manual.name_placeholder)}
onKeyDown={(e) => {
+ if (isImeComposing(e)) return;
if (e.key === "Enter") submit();
}}
/>
diff --git a/packages/views/workspace/create-workspace-form.tsx b/packages/views/workspace/create-workspace-form.tsx
index 9facfb2c09..4737c4d381 100644
--- a/packages/views/workspace/create-workspace-form.tsx
+++ b/packages/views/workspace/create-workspace-form.tsx
@@ -8,6 +8,7 @@ import { Button } from "@multica/ui/components/ui/button";
import { Card, CardContent } from "@multica/ui/components/ui/card";
import { useCreateWorkspace } from "@multica/core/workspace/mutations";
import type { Workspace } from "@multica/core/types";
+import { isImeComposing } from "@multica/core/utils";
import {
WORKSPACE_SLUG_REGEX,
isWorkspaceSlugConflict,
@@ -79,7 +80,10 @@ export function CreateWorkspaceForm({ onSuccess }: CreateWorkspaceFormProps) {
value={name}
onChange={(e) => handleNameChange(e.target.value)}
placeholder={t(($) => $.create_form.name_placeholder)}
- onKeyDown={(e) => e.key === "Enter" && handleCreate()}
+ onKeyDown={(e) => {
+ if (isImeComposing(e)) return;
+ if (e.key === "Enter") handleCreate();
+ }}
/>
</div>
<div className="space-y-1.5">
@@ -96,7 +100,10 @@ export function CreateWorkspaceForm({ onSuccess }: CreateWorkspaceFormProps) {
onChange={(e) => handleSlugChange(e.target.value)}
placeholder={t(($) => $.create_form.url_placeholder)}
className="border-0 shadow-none focus-visible:ring-0"
- onKeyDown={(e) => e.key === "Enter" && handleCreate()}
+ onKeyDown={(e) => {
+ if (isImeComposing(e)) return;
+ if (e.key === "Enter") handleCreate();
+ }}
/>
</div>
{slugError && (