From 7dbc1a5da868f85f99564e86368cc00157ce6d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=84=E9=BB=9B=E6=B7=B3=E5=8D=8E?= Date: Mon, 9 Dec 2024 16:29:50 +0800 Subject: [PATCH 1/7] fix Safari responds to the EnterKey from IM --- .../roosterjs-content-model-plugins/lib/edit/EditPlugin.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts b/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts index 87c4779ea85..c94899fe0af 100644 --- a/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts +++ b/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts @@ -181,7 +181,8 @@ export class EditPlugin implements EditorPlugin { break; case 'Enter': - if (!hasCtrlOrMetaKey) { + if (!hasCtrlOrMetaKey && event.rawEvent.keyCode == 13) { + // Safari responds to the EnterKey from IM, where IM should handle the key and the keycode is not 13. keyboardEnter(editor, rawEvent, this.handleNormalEnter); } break; From 27685bf6a1553a099c746d4188b5a3cdc0850c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=84=E9=BB=9B=E6=B7=B3=E5=8D=8E?= Date: Mon, 9 Dec 2024 16:52:55 +0800 Subject: [PATCH 2/7] fix test --- .../test/edit/EditPluginTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; From 73cc003a59946158a492ff4619c383c51a4327d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=84=E9=BB=9B=E6=B7=B3=E5=8D=8E?= Date: Tue, 10 Dec 2024 10:23:58 +0800 Subject: [PATCH 3/7] narrowing the scope of the if check --- packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts b/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts index c94899fe0af..01acb586253 100644 --- a/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts +++ b/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts @@ -181,7 +181,7 @@ export class EditPlugin implements EditorPlugin { break; case 'Enter': - if (!hasCtrlOrMetaKey && event.rawEvent.keyCode == 13) { + if (!hasCtrlOrMetaKey && event.rawEvent.keyCode !== 229) { // Safari responds to the EnterKey from IM, where IM should handle the key and the keycode is not 13. keyboardEnter(editor, rawEvent, this.handleNormalEnter); } From 601212ec01d07384d50a1034b42368d2b602d5e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=84=E9=BB=9B=E6=B7=B3=E5=8D=8E?= Date: Tue, 10 Dec 2024 10:54:58 +0800 Subject: [PATCH 4/7] Add comment --- .../lib/edit/EditPlugin.ts | 7 +++++-- .../lib/edit/keyCode.ts | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts diff --git a/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts b/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts index 01acb586253..809071f72a3 100644 --- a/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts +++ b/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts @@ -181,8 +181,11 @@ export class EditPlugin implements EditorPlugin { break; case 'Enter': - if (!hasCtrlOrMetaKey && event.rawEvent.keyCode !== 229) { - // Safari responds to the EnterKey from IM, where IM should handle the key and the keycode is not 13. + if ( + !hasCtrlOrMetaKey && + !event.rawEvent.isComposing && + event.rawEvent.keyCode !== KeyCode.dead + ) { keyboardEnter(editor, rawEvent, this.handleNormalEnter); } break; diff --git a/packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts b/packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts new file mode 100644 index 00000000000..f94bb6b982c --- /dev/null +++ b/packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts @@ -0,0 +1,13 @@ +/** + * Key code enumeration + * https://www.toptal.com/developers/keycode/table + */ +const enum KeyCode { + /** + * 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 + */ + dead = 229, +} From 7fad0256a8a8ffacec8647a8d58b2bcb0dd812c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=84=E9=BB=9B=E6=B7=B3=E5=8D=8E?= Date: Tue, 10 Dec 2024 10:58:36 +0800 Subject: [PATCH 5/7] fix build --- packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts | 1 + packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts b/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts index 809071f72a3..775e5e0e23c 100644 --- a/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts +++ b/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts @@ -2,6 +2,7 @@ import { keyboardDelete } from './keyboardDelete'; import { keyboardEnter } from './keyboardEnter'; import { keyboardInput } from './keyboardInput'; import { keyboardTab } from './keyboardTab'; +import { KeyCode } from './keyCode'; import { parseTableCells } from 'roosterjs-content-model-dom'; import type { DOMSelection, diff --git a/packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts b/packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts index f94bb6b982c..f92d743cad3 100644 --- a/packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts +++ b/packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts @@ -2,7 +2,7 @@ * Key code enumeration * https://www.toptal.com/developers/keycode/table */ -const enum KeyCode { +export const enum KeyCode { /** * 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. From 056689faf21c6cedfd3ec082010e23721a465aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=84=E9=BB=9B=E6=B7=B3=E5=8D=8E?= Date: Tue, 10 Dec 2024 10:59:46 +0800 Subject: [PATCH 6/7] remove comment --- packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts b/packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts index f92d743cad3..31873d44998 100644 --- a/packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts +++ b/packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts @@ -1,6 +1,5 @@ /** * Key code enumeration - * https://www.toptal.com/developers/keycode/table */ export const enum KeyCode { /** From 3e908c102eeae47cc403b4bdccfdf0ec1a2696bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=84=E9=BB=9B=E6=B7=B3=E5=8D=8E?= Date: Wed, 11 Dec 2024 13:15:43 +0800 Subject: [PATCH 7/7] address to comment --- .../lib/edit/EditPlugin.ts | 10 ++++++++-- .../lib/edit/keyCode.ts | 12 ------------ 2 files changed, 8 insertions(+), 14 deletions(-) delete mode 100644 packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts diff --git a/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts b/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts index 775e5e0e23c..d0c1263a2c1 100644 --- a/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts +++ b/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts @@ -2,7 +2,6 @@ import { keyboardDelete } from './keyboardDelete'; import { keyboardEnter } from './keyboardEnter'; import { keyboardInput } from './keyboardInput'; import { keyboardTab } from './keyboardTab'; -import { KeyCode } from './keyCode'; import { parseTableCells } from 'roosterjs-content-model-dom'; import type { DOMSelection, @@ -24,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, @@ -185,7 +191,7 @@ export class EditPlugin implements EditorPlugin { if ( !hasCtrlOrMetaKey && !event.rawEvent.isComposing && - event.rawEvent.keyCode !== KeyCode.dead + event.rawEvent.keyCode !== DEAD_KEY ) { keyboardEnter(editor, rawEvent, this.handleNormalEnter); } diff --git a/packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts b/packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts deleted file mode 100644 index 31873d44998..00000000000 --- a/packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Key code enumeration - */ -export const enum KeyCode { - /** - * 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 - */ - dead = 229, -}