Skip to content

Commit

Permalink
fix Safari responds to the EnterKey from IM (#2901)
Browse files Browse the repository at this point in the history
* fix Safari responds to the EnterKey from IM

* fix test

* narrowing the scope of the if check

* Add comment

* fix build

* remove comment

* address to comment

---------

Co-authored-by: Jiuqing Song <jisong@microsoft.com>
  • Loading branch information
miku1958 and JiuqingSong authored Dec 11, 2024
1 parent 0f788b1 commit db04e83
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<EditOptions> = {
handleTabKey: true,
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit db04e83

Please sign in to comment.