diff --git a/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts b/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts index 87c4779ea85..d0c1263a2c1 100644 --- a/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts +++ b/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts @@ -23,6 +23,13 @@ export type EditOptions = { const BACKSPACE_KEY = 8; const DELETE_KEY = 46; +/** + * According to https://lists.w3.org/Archives/Public/www-dom/2010JulSep/att-0182/keyCode-spec.html + * 229 can be sent in variants generated when Long press (iOS) or using IM. + * + * Other cases: https://stackoverflow.com/questions/25043934/is-it-ok-to-ignore-keydown-events-with-keycode-229 + */ +const DEAD_KEY = 229; const DefaultOptions: Partial = { handleTabKey: true, @@ -181,7 +188,11 @@ export class EditPlugin implements EditorPlugin { break; case 'Enter': - if (!hasCtrlOrMetaKey) { + if ( + !hasCtrlOrMetaKey && + !event.rawEvent.isComposing && + event.rawEvent.keyCode !== DEAD_KEY + ) { keyboardEnter(editor, rawEvent, this.handleNormalEnter); } break; diff --git a/packages/roosterjs-content-model-plugins/test/edit/EditPluginTest.ts b/packages/roosterjs-content-model-plugins/test/edit/EditPluginTest.ts index 51e2c32bccd..7e94b272ad0 100644 --- a/packages/roosterjs-content-model-plugins/test/edit/EditPluginTest.ts +++ b/packages/roosterjs-content-model-plugins/test/edit/EditPluginTest.ts @@ -142,7 +142,7 @@ describe('EditPlugin', () => { it('Enter, normal enter not enabled', () => { plugin = new EditPlugin(); - const rawEvent = { which: 13, key: 'Enter' } as any; + const rawEvent = { keyCode: 13, which: 13, key: 'Enter' } as any; const addUndoSnapshotSpy = jasmine.createSpy('addUndoSnapshot'); editor.takeSnapshot = addUndoSnapshotSpy; @@ -165,7 +165,7 @@ describe('EditPlugin', () => { (featureName: string) => featureName == 'HandleEnterKey' ); plugin = new EditPlugin(); - const rawEvent = { which: 13, key: 'Enter' } as any; + const rawEvent = { keyCode: 13, which: 13, key: 'Enter' } as any; const addUndoSnapshotSpy = jasmine.createSpy('addUndoSnapshot'); editor.takeSnapshot = addUndoSnapshotSpy;