Files
apes-sidebar/scripts/apply-ime-guard.mjs
T
taekchef a465bdee38 fix(ime): 持久化 IME 守卫脚本并挂入 build/prepare/bundle 构建路径
- scripts/apply-ime-guard.mjs 纳入版本库(此前 untracked,重 clone 即丢)
- Univer InputNumber 在 document capture 拦截全页 ↑/↓ 且无 isComposing
  守卫,会摧毁中文输入法组合;prepare/bundle 裸 tsdown 重建会产出无守卫
  的 lib/client.js,2026-08-11 因此复发(dsh-external/issues#562)
- 脚本幂等:已注入则跳过;目标模式匹配不到则 exit 1 显式失败

Fixes #562
2026-08-12 03:13:31 +08:00

27 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 持久 IME 守卫补丁(2026-08-10,changelog 见 AGENTS.md):
// Univer InputNumber 在 document capture 拦截全页 ↑/↓ 且无 isComposing 守卫,
// 会摧毁中文输入法组合(候选词导航被劫持)。每次 build 后自动重打。
import { readFileSync, writeFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { dirname, join } from 'node:path'
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
const target = join(root, 'lib/client.js')
const src = readFileSync(target, 'utf8')
const pattern = /function handleKeyDown\(e\) \{(\s*)if \(disabled\) return;/
const guard = 'function handleKeyDown(e) {\n\t\t\t\t\tif (e.isComposing || e.keyCode === 229) return;\n\t\t\t\t\tif (disabled) return;'
if (src.includes('e.isComposing || e.keyCode === 229')) {
console.log('[apply-ime-guard] guard already present, skip')
process.exit(0)
}
const count = src.match(new RegExp(pattern.source, 'g'))?.length ?? 0
if (count === 0) {
console.error('[apply-ime-guard] ERROR: pattern not found in lib/client.js — univer structure may have changed, inspect manually!')
process.exit(1)
}
const next = src.replace(pattern, guard)
writeFileSync(target, next)
console.log(`[apply-ime-guard] injected IME guard (${count} site(s))`)