From 7eccc49f6ebbbde71802d88277f0dd8d1d0f2c97 Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Wed, 12 Aug 2026 14:41:36 +0800 Subject: [PATCH] =?UTF-8?q?revert:=20=E7=A7=BB=E9=99=A4=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E6=9C=9F=20IME=20=E5=AE=88=E5=8D=AB=E8=A1=A5=E4=B8=81=20?= =?UTF-8?q?=E2=80=94=20=E8=A1=A5=E4=B8=81=E6=89=93=E5=9C=A8=E4=BA=A7?= =?UTF-8?q?=E7=89=A9=E4=B8=8A=E4=B8=8D=E5=85=B7=E6=8C=81=E4=B9=85=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit taekchef 的 apply-ime-guard.mjs 在每次 build/prepare/bundle 后把守卫 字符串注入 lib/client.js,但补丁对象是构建产物而非源码: - 裸 tsdown 重建 / 其他构建路径产出无守卫的 bundle(#562 复发根因) - 守卫逻辑游离于源码之外,难以测试与维护 运行时方案(src/client/ime-guard.ts + tests/ime-guard.spec.ts)已在 源码内实现同等守卫,经 document capture 覆盖全部劫持路径,任何构建 方式产物都自带守卫。合并远端提交后撤掉构建期补丁,保留运行时方案。 --- package.json | 6 +++--- scripts/apply-ime-guard.mjs | 26 -------------------------- 2 files changed, 3 insertions(+), 29 deletions(-) delete mode 100644 scripts/apply-ime-guard.mjs diff --git a/package.json b/package.json index 52abebe..2405ef3 100644 --- a/package.json +++ b/package.json @@ -51,11 +51,11 @@ "src" ], "scripts": { - "build": "rm -rf lib && tsc -p tsconfig.build.json && tsdown && node scripts/apply-ime-guard.mjs", + "build": "rm -rf lib && tsc -p tsconfig.build.json && tsdown", "typecheck": "tsc --noEmit", - "bundle": "tsdown && node scripts/apply-ime-guard.mjs", + "bundle": "tsdown", "watch": "tsdown --watch", - "prepare": "tsdown && node scripts/apply-ime-guard.mjs", + "prepare": "tsdown", "test": "vitest run" }, "license": "MIT", diff --git a/scripts/apply-ime-guard.mjs b/scripts/apply-ime-guard.mjs deleted file mode 100644 index 97c6c1a..0000000 --- a/scripts/apply-ime-guard.mjs +++ /dev/null @@ -1,26 +0,0 @@ -// 持久 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))`)