Files
openchamber/packages/ui/src/lib/ime.ts
T

16 lines
616 B
TypeScript
Raw Normal View History

2026-01-06 21:31:04 +02:00
import type React from 'react';
/**
* Detects if a keyboard event is part of IME composition.
* Uses both `isComposing` and the `keyCode === 229` fallback.
*
* Note: `keyCode` is deprecated, but `229` remains a practical fallback for
* some WebKit-based environments where composition
2026-01-06 21:31:04 +02:00
* events can be ordered unexpectedly.
*/
export const isIMECompositionEvent = (e: KeyboardEvent | React.KeyboardEvent): boolean => {
// CodeMirror keymaps hand out the native event; React handlers wrap it.
const native = 'nativeEvent' in e ? e.nativeEvent : e;
return native.isComposing || native.keyCode === 229;
2026-01-06 21:31:04 +02:00
};