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
|
2026-06-03 02:42:00 +03:00
|
|
|
* some WebKit-based environments where composition
|
2026-01-06 21:31:04 +02:00
|
|
|
* events can be ordered unexpectedly.
|
|
|
|
|
*/
|
2026-07-27 22:21:38 +03:00
|
|
|
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
|
|
|
};
|