fix(tui): avoid inserting spaces into long CJK text (#78765) · openclaw/openclaw@c082a3b
hpt
·
2026-06-16
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -376,6 +376,23 @@ describe("sanitizeRenderableText", () => {
|
376 | 376 | expectTokenWidthUnderLimit(input); |
377 | 377 | }); |
378 | 378 | |
| 379 | +it("preserves long CJK prose without inserting display spaces", () => { |
| 380 | +const input = |
| 381 | +"特蕾莎修女是一个极端投入极有宗教信念愿意亲身服务底层苦难者的人但她不是现代公共卫生意义上的慈善改革者"; |
| 382 | +const sanitized = sanitizeRenderableText(input); |
| 383 | + |
| 384 | +expect(sanitized).toBe(input); |
| 385 | +expect(sanitized).not.toContain("苦难 者"); |
| 386 | +}); |
| 387 | + |
| 388 | +it("preserves mixed long CJK prose without inserting display spaces", () => { |
| 389 | +const input = |
| 390 | +"MotherTeresa更像是宗教慈悲的象征而不是现代慈善治理的典范她值得尊重的地方是真实走进极端苦难"; |
| 391 | +const sanitized = sanitizeRenderableText(input); |
| 392 | + |
| 393 | +expect(sanitized).toBe(input); |
| 394 | +}); |
| 395 | + |
379 | 396 | it("preserves long filesystem paths verbatim for copy safety", () => { |
380 | 397 | const input = |
381 | 398 | "/Users/jasonshawn/PerfectXiao/a_very_long_directory_name_designed_specifically_to_test_the_line_wrapping_issue/file.txt"; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -19,6 +19,7 @@ const EDGE_PUNCTUATION_RE = /^[`"'([{<]+|[`"')\]}>.,:;!?]+$/g;
|
19 | 19 | const ALPHANUMERIC_RE = /[A-Za-z0-9]/; |
20 | 20 | const TOKENISH_MIN_LENGTH = 24; |
21 | 21 | const RTL_SCRIPT_RE = /[\u0590-\u08ff\ufb1d-\ufdff\ufe70-\ufefc]/; |
| 22 | +const CJK_SCRIPT_RE = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u; |
22 | 23 | const BIDI_CONTROL_RE = /[\u202a-\u202e\u2066-\u2069]/; |
23 | 24 | const RTL_ISOLATE_START = "\u2067"; |
24 | 25 | const RTL_ISOLATE_END = "\u2069"; |
@@ -110,6 +111,12 @@ function normalizeLongTokenForDisplay(token: string): string {
|
110 | 111 | if (isCopySensitiveToken(token)) { |
111 | 112 | return token; |
112 | 113 | } |
| 114 | +// CJK text naturally appears without spaces between words. Inserting spaces |
| 115 | +// into long CJK runs makes assistant prose render with visible artifacts such |
| 116 | +// as "苦难 者". Let the TUI renderer wrap these runs at grapheme boundaries. |
| 117 | +if (CJK_SCRIPT_RE.test(token)) { |
| 118 | +return token; |
| 119 | +} |
113 | 120 | // Pure symbol/punctuation runs (table borders made of `─`, `=`, `-`) carry |
114 | 121 | // no copyable identifier; chunking would corrupt the visible structure. |
115 | 122 | if (!ALPHANUMERIC_RE.test(token)) { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。