🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(page-editor): ignore IME composition Enter in page title (#21206)
Lobehub Coder971acea42975
diff --git a/src/features/PageEditor/PageEditor.test.tsx b/src/features/PageEditor/PageEditor.test.tsxindex 6945639821c..75a2172433b 100644--- a/src/features/PageEditor/PageEditor.test.tsx+++ b/src/features/PageEditor/PageEditor.test.tsx@@ -2,7 +2,7 @@ import { renderHook } from '@testing-library/react';import { useEffect } from 'react';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { getTitleTextAreaInteractionProps } from './TitleSection';+import { getTitleTextAreaInteractionProps, isTitleSubmitKey } from './TitleSection';describe('PageEditor title interaction', () => {it('keeps a non-editable title visually enabled but read-only', () => {@@ -12,6 +12,25 @@ describe('PageEditor title interaction', () => {expect(props).not.toHaveProperty('disabled');expect(getTitleTextAreaInteractionProps(true)).toEqual({ readOnly: false });});++ it('submits the title on a plain Enter', () => {+ expect(+ isTitleSubmitKey({ key: 'Enter', keyCode: 13, nativeEvent: { isComposing: false } }),+ ).toBe(true);+ expect(isTitleSubmitKey({ key: 'a', keyCode: 65, nativeEvent: { isComposing: false } })).toBe(+ false,+ );+ });++ it('ignores Enter that confirms an IME composition', () => {+ expect(+ isTitleSubmitKey({ key: 'Enter', keyCode: 13, nativeEvent: { isComposing: true } }),+ ).toBe(false);+ // Safari fires the confirming keydown after compositionend with keyCode 229+ expect(+ isTitleSubmitKey({ key: 'Enter', keyCode: 229, nativeEvent: { isComposing: false } }),+ ).toBe(false);+ });});describe('PageEditor beforeunload handler', () => {diff --git a/src/features/PageEditor/TitleSection.tsx b/src/features/PageEditor/TitleSection.tsxindex 908c08c705e..37835da20c0 100644--- a/src/features/PageEditor/TitleSection.tsx+++ b/src/features/PageEditor/TitleSection.tsx@@ -19,6 +19,15 @@ export const getTitleTextAreaInteractionProps = (canEdit: boolean) => ({readOnly: !canEdit,});+// Enter that confirms an IME candidate (Chinese/Japanese input) must not submit+// the title: moving focus to the body mid-composition commits the text there too.+// Safari reports the confirming keydown with isComposing=false but keyCode 229.+export const isTitleSubmitKey = (e: {+ key: string;+ keyCode?: number;+ nativeEvent?: { isComposing?: boolean };+}) => e.key === 'Enter' && !e.nativeEvent?.isComposing && e.keyCode !== 229;+const TitleSection = memo(() => {const { t } = useTranslation('file');const locale = useGlobalStore(globalGeneralSelectors.currentLanguage);@@ -137,7 +146,7 @@ const TitleSection = memo(() => {onKeyDown={(e) => {if (!canEdit) return;- if (e.key === 'Enter') {+ if (isTitleSubmitKey(e)) {e.preventDefault();handleTitleSubmit();}