Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Safari responds to the EnterKey from IM #2901

Merged
merged 8 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading