Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(editor): guard Mod-Enter submit against open IME composition (#5231)
Jiayuan Zhang932bbf2bb501
diff --git a/packages/views/editor/extensions/submit-shortcut.test.ts b/packages/views/editor/extensions/submit-shortcut.test.tsindex 4044214473..65c4dafb30 100644--- a/packages/views/editor/extensions/submit-shortcut.test.ts+++ b/packages/views/editor/extensions/submit-shortcut.test.ts@@ -25,7 +25,7 @@ describe("createSubmitExtension", () => {isActive: () => false,} as Partial<Editor>;- it("Mod-Enter always submits", () => {+ it("Mod-Enter submits when no composition is open", () => {const onSubmit = vi.fn(() => true);const shortcuts = getShortcuts(createSubmitExtension(onSubmit, { submitOnEnter: false }),@@ -33,10 +33,24 @@ describe("createSubmitExtension", () => {);expect(shortcuts["Mod-Enter"]).toBeDefined();- shortcuts["Mod-Enter"]!();+ expect(shortcuts["Mod-Enter"]!()).toBe(true);expect(onSubmit).toHaveBeenCalledTimes(1);});+ it("Mod-Enter is suppressed during IME composition", () => {+ const onSubmit = vi.fn(() => true);+ const shortcuts = getShortcuts(+ createSubmitExtension(onSubmit, { submitOnEnter: false }),+ {+ view: { composing: true } as unknown as Editor["view"],+ isActive: () => false,+ },+ );++ expect(shortcuts["Mod-Enter"]!()).toBe(false);+ expect(onSubmit).not.toHaveBeenCalled();+ });+it("bare Enter is not bound when submitOnEnter is false", () => {const onSubmit = vi.fn(() => true);const shortcuts = getShortcuts(diff --git a/packages/views/editor/extensions/submit-shortcut.ts b/packages/views/editor/extensions/submit-shortcut.tsindex aea7b1904b..94654e2f98 100644--- a/packages/views/editor/extensions/submit-shortcut.ts+++ b/packages/views/editor/extensions/submit-shortcut.ts@@ -16,7 +16,15 @@ export function createSubmitExtension(name: "submitShortcut",addKeyboardShortcuts() {const shortcuts: Record<string, () => boolean> = {- "Mod-Enter": () => onSubmit(),+ "Mod-Enter": () => {+ // IME guard — same as Enter below. While a composition is open the+ // composed text is not in the document yet, so submitting here+ // would send the doc WITHOUT what the user just typed (e.g. paste+ // a screenshot, type a pinyin sentence, hit ⌘↵ before the buffer+ // commits — the submission carries only the screenshot).+ if (this.editor.view.composing) return false;+ return onSubmit();+ },};if (submitOnEnter) {shortcuts.Enter = () => {