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 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -181,7 +182,11 @@ export class EditPlugin implements EditorPlugin {
break;

case 'Enter':
if (!hasCtrlOrMetaKey) {
if (
!hasCtrlOrMetaKey &&
!event.rawEvent.isComposing &&
event.rawEvent.keyCode !== KeyCode.dead
) {
keyboardEnter(editor, rawEvent, this.handleNormalEnter);
}
break;
Expand Down
12 changes: 12 additions & 0 deletions packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Key code enumeration
*/
export const enum KeyCode {

Check failure on line 4 in packages/roosterjs-content-model-plugins/lib/edit/keyCode.ts

View workflow job for this annotation

GitHub Actions / build

`const enum` is forbidden
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just put it back in EditPlugin.ts and no need to export it.
And use a regular const instead of const enum since const enum has a lot of problem.

/**
* 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,
}
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