Skip to content
Merged
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
15 changes: 14 additions & 1 deletion src/libs/KeyboardShortcut/isEnterWhileComposition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,23 @@ const isEnterWhileComposition = (event: KeyboardEvent | React.KeyboardEvent): bo
// On Safari, isComposing returns false on Enter keypress event even for IME confirmation. Although keyCode is deprecated,
// reading keyCode is the only way available to distinguish Enter keypress event for IME confirmation.
if (CONST.BROWSER.SAFARI === Browser.getBrowser()) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return event.keyCode === 229;
Comment thread
nkdengineer marked this conversation as resolved.
}

return event.key === CONST.KEYBOARD_SHORTCUTS.ENTER.shortcutKey && (event as unknown as NativeSyntheticEvent<KeyboardEvent>)?.nativeEvent?.isComposing;
// Check if this is a native KeyboardEvent (has isComposing directly) or a React synthetic event (has nativeEvent.isComposing)
// For native KeyboardEvent, isComposing is directly on the event
// For React synthetic events, it's on event.nativeEvent.isComposing
let isComposing: boolean | undefined;

if (event instanceof KeyboardEvent) {
isComposing = event.isComposing;
Comment thread
nkdengineer marked this conversation as resolved.
} else {
const nativeEvent = (event as unknown as NativeSyntheticEvent<KeyboardEvent>)?.nativeEvent;
isComposing = nativeEvent?.isComposing;
}

return event.key === CONST.KEYBOARD_SHORTCUTS.ENTER.shortcutKey && !!isComposing;
};

export default isEnterWhileComposition;
Loading