From a465bdee3895330c8d100c954a16363e57589333 Mon Sep 17 00:00:00 2001 From: taekchef Date: Wed, 12 Aug 2026 03:13:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(ime):=20=E6=8C=81=E4=B9=85=E5=8C=96=20IME?= =?UTF-8?q?=20=E5=AE=88=E5=8D=AB=E8=84=9A=E6=9C=AC=E5=B9=B6=E6=8C=82?= =?UTF-8?q?=E5=85=A5=20build/prepare/bundle=20=E6=9E=84=E5=BB=BA=E8=B7=AF?= =?UTF-8?q?=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- package.json | 6 +++--- scripts/apply-ime-guard.mjs | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 scripts/apply-ime-guard.mjs diff --git a/package.json b/package.json index 867424c..6f21cb9 100644 --- a/package.json +++ b/package.json @@ -51,11 +51,11 @@ "src" ], "scripts": { - "build": "rm -rf lib && tsc -p tsconfig.build.json && tsdown", + "build": "rm -rf lib && tsc -p tsconfig.build.json && tsdown && node scripts/apply-ime-guard.mjs", "typecheck": "tsc --noEmit", - "bundle": "tsdown", + "bundle": "tsdown && node scripts/apply-ime-guard.mjs", "watch": "tsdown --watch", - "prepare": "tsdown", + "prepare": "tsdown && node scripts/apply-ime-guard.mjs", "test": "vitest run" }, "license": "MIT", diff --git a/scripts/apply-ime-guard.mjs b/scripts/apply-ime-guard.mjs new file mode 100644 index 0000000..97c6c1a --- /dev/null +++ b/scripts/apply-ime-guard.mjs @@ -0,0 +1,26 @@ +// 持久 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))`)