Repository navigation
fix(chat): render mixed RTL/LTR paragraphs with content-aware direction - #2389
Merged
Merged
Conversation
Paragraph base direction followed the first strong character, so a Persian/Arabic paragraph opening with an English word rendered LTR and its RTL runs, punctuation, and parentheses scrambled (vastsa#2388). - New lib/text-direction counts strong LTR/RTL characters per paragraph; the majority script picks the base direction, neutral text stays auto. - Markdown paragraph and list-item renderers set the computed dir on every rendered block. - User message bubbles get the same computed dir on the text container. - Inline chips, links, and prose emphasis isolate (unicode-bidi) so surrounding punctuation cannot migrate across them; the composer and the message-edit textarea use per-paragraph plaintext auto direction.
vastsa
requested changes
Nov 16, 2026
vastsa
left a comment
Owner
There was a problem hiding this comment.
现有 8 个 text-direction 测试通过,但直接执行生产函数发现 RTL_STRONG 漏掉波斯字母 پ/چ/ژ/گ,并把阿拉伯问号/分号等中性标点计作 strong RTL。实测 countStrongCharacters("پژگچ") 返回 {ltr:0,rtl:0},directionAttr("... ؟ ؛") 返回 rtl;"hello چپ چپ چپ چپ چپ" 返回 {ltr:5,rtl:0},强制 ltr,复现本 PR 要修的英文开头、波斯语占多数错误方向。
请可靠区分 Unicode 强方向字母、数字、标点、组合符,覆盖完整波斯字母并增加以上反例。另外 MessageRow 对整条多段消息只算一个 dir,无法满足每段独立方向;请覆盖同一消息包含英文段落与波斯文段落的真实渲染路径。现有后 3 项是源码正则断言,不能证明实际 DOM 和混排顺序;请增加组件/浏览器用户路径验证,覆盖气泡、Markdown 和 composer 的方向与标点表现后再合入。
4 tasks done
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.
根因 (Root cause)
聊天段落依赖第一个强方向字符时,英文开头、波斯文占多数的段落会被判成 LTR。原分类还漏掉
پچژگ,并把؟、؛等标点当作 RTL 强字符。整条消息共用一个方向也无法正确显示英文和波斯文分段。修复 (Fix)
LinkifiedText、附件位置及源码偏移。unicode-bidi: plaintext,按每段 first-strong 规则编辑。ChatTranscript→MessageRow/Markdown、ComposerInput与生产编辑器绘制函数的 Chromium DOM 验证。验证 (Verification)
tsc -p apps/desktop/tsconfig.json --noEmit通过;另用继承 desktop 配置的临时项目包含新scripts/e2e/bidi-direction.tsx,生产组件和新探针一起通过 strict typecheck。UnicodeData.txt,对生产countStrongCharacters检查全部 40,575 条显式记录,含 2,611 个 RTL 字母,零分类差异;26 个 Bidi_Class=ON 的 modifier letters 也不投票(本地 Node Unicode 版本 17.0)。CHROMIUM_BINARY=<installed-browser> node scripts/e2e-bidi.mjs通过:同一气泡与 Markdown 分别得到 LTR/RTL 段落,列表项方向独立,行内强调隔离;生产 composer 绘制混合草稿后内容往返不变,Range 实际字形位置验证英文与波斯文标点顺序,气泡和 Markdown 的波斯问号位置也经过字形几何断言。biome.json范围 lint、style tokens、git diff --check通过;仓库 formatter 禁用,未进行全文件格式化。Fixes #2388