e4dcfc49aa
Tests / Import Check (Python 3.13) (push) Has been cancelled
Tests / Import Check (Python 3.14) (push) Has been cancelled
Tests / Python Tests (Python 3.11) (push) Has been cancelled
Tests / Python Tests (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.14) (push) Has been cancelled
Tests / Test Summary (push) Has been cancelled
Tests / Lint and Format (push) Has been cancelled
Tests / Web Node Tests (push) Has been cancelled
Tests / Import Check (Python 3.11) (push) Has been cancelled
Tests / Import Check (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.13) (push) Has been cancelled
42 lines
951 B
TypeScript
42 lines
951 B
TypeScript
export interface KeyboardSubmitEventLike {
|
|
key: string;
|
|
shiftKey?: boolean;
|
|
isComposing?: boolean;
|
|
keyCode?: number;
|
|
which?: number;
|
|
nativeEvent?: {
|
|
isComposing?: boolean;
|
|
keyCode?: number;
|
|
which?: number;
|
|
};
|
|
}
|
|
|
|
const IME_PROCESS_KEY_CODE = 229;
|
|
|
|
export function isImeComposing(
|
|
event: KeyboardSubmitEventLike,
|
|
compositionActive = false,
|
|
): boolean {
|
|
const nativeEvent = event.nativeEvent;
|
|
return Boolean(
|
|
compositionActive ||
|
|
event.isComposing ||
|
|
nativeEvent?.isComposing ||
|
|
event.keyCode === IME_PROCESS_KEY_CODE ||
|
|
event.which === IME_PROCESS_KEY_CODE ||
|
|
nativeEvent?.keyCode === IME_PROCESS_KEY_CODE ||
|
|
nativeEvent?.which === IME_PROCESS_KEY_CODE,
|
|
);
|
|
}
|
|
|
|
export function shouldSubmitOnEnter(
|
|
event: KeyboardSubmitEventLike,
|
|
compositionActive = false,
|
|
): boolean {
|
|
return (
|
|
event.key === "Enter" &&
|
|
!event.shiftKey &&
|
|
!isImeComposing(event, compositionActive)
|
|
);
|
|
}
|