Repository navigation
fix(shared): 中文风险文本按显示列宽折行,分享卡不再溢出 - #248
Merged
Merged
Conversation
wrapText() 按空白分词,中文句子没有词间空格,整句被当成一个不可断的 「单词」原样输出:既不折行,也不会触发 112 字截断分支。59 个全角字因此 以单行 767px 溢出 640px 卡片的 576px 内容区,keyRiskLines() 注释中承诺的 「至多两行」在中文下失效。 改为按显示列宽折行: - 全角字(CJK 表意文字与标点、假名、谚文、全角形式)计 2 列; - 在 CJK 字之间提供断点,与日常 CJK 断行规则一致; - 保留既有语义:拉丁词内部仍不断开,词间空白原样保留,超出预算的单个 不可断原子仍独占一行。 keyRiskLines() 的 112 列预算同步改为列宽口径,并为省略号预留 1 列,使 「至多两行」的承诺在中文下也成立。 Closes helsome#247
helsome
approved these changes
Oct 18, 2026
helsome
left a comment
Owner
There was a problem hiding this comment.
独立代码审查及精确 HEAD focused 31/0 通过。按当前顺序累计组合完整测试1924 pass / 7 skip / 0 fail、全workspace typecheck、i18n通过,secret扫描零命中。相关货币/排版确定性回归符合本PR范围,不将其声称为全桌面或真实模型E2E。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #247
问题
packages/shared/src/export/card.ts的wrapText()按空白分词(text.split(/\s+/))。中文句子没有词间空格,整句被当成一个不可断的「单词」原样返回,于是:MAX_CHARS = 112的截断分支,…不会追加。zh-CN 是受支持的 locale,
kernelHost.ts的reportToShareCard(redactForShare(report))会走到这里。59 个全角字的常见风险句以单行 767px 溢出 640px 卡片的 576px 内容区(超出约 33%)。改动
packages/shared/src/export/card.tswrapText(text, maxColumns)改为按显示列宽折行:FULL_WIDTH_RE/isFullWidth():识别 CJK 表意文字与标点、假名、谚文、全角形式;displayWidth():全角字计 2 列,与卡片字体栈中的实际推进宽度一致;atomize():把文本切成「最小不可断原子 + 其前置空白」。断点出现在空白之后与 CJK 字之间,拉丁字符连续段保持为一个原子;displayWidth(joined),词间空白按原样拼接(不再统一替换成单个空格)。keyRiskLines()的 112 列预算同步改为列宽口径,并用clampToColumns()为省略号预留 1 列——否则截断后再拼…会多出 1 列,把两行撑成三行。保留的语义(均有既有用例守着):
wrapText('supercalifragilistic', 5)仍返回['supercalifragilistic'];wrapText('one two three four', 9)仍为['one two', 'three', 'four'];[];确定性渲染(相同输入 → 相同字节)不变。测试
packages/shared/src/export/card.test.ts新增 3 条:breaks CJK text between ideographs — it has no whitespace to split onwrapText('中文测试中文测试', 6)→['中文测', '试中文', '测试']keeps the whitespace that separates mixed CJK and Latin atomswrapText('AAPL 上涨明显', 10)→['AAPL 上涨', '明显']wraps a whitespace-free CJK key risk into the two-line risk block…TDD 证据:
修复后实测:
门禁:
cd packages/shared && bun run typecheck→ 0 errorbun test packages/shared/src/export→ 31 pass / 0 fail说明
wrapText的第二个参数由maxChars更名为maxColumns(位置参数,调用方不受影响),因为度量单位从「码元数」变成了「显示列数」。