All checks were successful
Build and Deploy Front / deploy (push) Successful in 4m2s
Co-authored-by: Cursor <cursoragent@cursor.com>
23 lines
735 B
TypeScript
23 lines
735 B
TypeScript
/**
|
||
* 键盘 / IME 相关工具(Mac 拼音组字、跨端修饰键等)
|
||
*/
|
||
|
||
/** 中文等 IME 组字过程中:不应触发扫描回车 / 提交 */
|
||
export function isImeComposingEvent(e: unknown): boolean {
|
||
if (!e || typeof e !== 'object') return false
|
||
const ev = e as KeyboardEvent & { keyCode?: number }
|
||
if (ev.isComposing) return true
|
||
if (ev.key === 'Process') return true
|
||
// 旧浏览器 / 部分输入法仍用 229
|
||
if (typeof ev.keyCode === 'number' && ev.keyCode === 229) return true
|
||
return false
|
||
}
|
||
|
||
/** 包装无参回车处理:组字中直接忽略 */
|
||
export function withImeEnterGuard(fn: () => void | Promise<void>) {
|
||
return (e?: Event) => {
|
||
if (isImeComposingEvent(e)) return
|
||
void fn()
|
||
}
|
||
}
|