Skip to content

fix: disable BiDi for Uyghur/Tibetan locales - #591

Draft
pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/agent/1f32cbb7425a
Draft

pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/agent/1f32cbb7425a

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

When the terminal locale is set to ug_CN (Uyghur) or bo_CN (Tibetan), TermWidget::TermWidget calls setBidiEnabled(true), enabling Qt's BiDi text reordering. BiDi reordering visually rearranges mixed RTL/LTR text, but the reordered glyph positions no longer align with the terminal's fixed-width cell grid (_fontWidth * len), causing display misalignment when running commands like uos-activator-cmd -q that output mixed RTL labels and LTR values (analysis-report.md section 6).

Key evidence: TerminalDisplay.cpp:886-898 — BiDi path uses drawText(QPointF, text) with cell-grid-left anchoring; TerminalDisplay.cpp:446 — _bidiEnabled defaults to true, so merely removing the setBidiEnabled(true) call does not disable BiDi.

Fix

Explicitly call setBidiEnabled(false) for ug_CN/bo_CN at src/views/termwidget.cpp:180, forcing RTL text through the LTR override path (LTR_OVERRIDE_CHAR(U+202D) + AlignBottom), which keeps glyph positions aligned with the cell grid. This matches analysis-report.md section 10 (symptom-layer patch) with no deviation.

Change Safety Assessment

Code Safety

  • Risk Level: Medium
  • Reverses design decision introduced by commit fdcad090 (2021-03-16), which enabled BiDi for Uyghur/Tibetan to provide RTL visual reading order. This reversal is explicitly approved by BugFix-leader-2.0.
  • setBidiEnabled is called only once in TermWidget constructor; change-safety-raw.json references are empty (reference_count: 0), no other callers affected.

Business Impact Scope

Only Uyghur (ug_CN) and Tibetan (bo_CN) terminal rendering paths are affected — text in these locales will display in logical (LTR) order instead of RTL visual order. All other locales (zh_CN, en_US, etc.) are completely unaffected. User scenario: running uos-activator-cmd -q or any command producing mixed RTL/LTR output in Uyghur/Tibetan environment.

Verification Suggestion

Test uos-activator-cmd -q output alignment in ug_CN locale; verify terminal output alignment in bo_CN; confirm no regression in zh_CN/en_US.


根因分析

当终端语言环境为 ug_CN(维语)或 bo_CN(藏语)时,TermWidget::TermWidget 调用 setBidiEnabled(true) 启用 Qt BiDi 文本重排。BiDi 重排对混合 RTL/LTR 文本做视觉重排,重排后字符位置与终端固定宽度 cell 网格(_fontWidth * len)不对应,导致运行 uos-activator-cmd -q 等输出混合 RTL 标签与 LTR 值的命令时显示错位(analysis-report.md 第六节)。

关键证据:TerminalDisplay.cpp:886-898 — BiDi 路径用 drawText(QPointF, text) 以 cell 网格左边界为锚点;TerminalDisplay.cpp:446 — _bidiEnabled 默认为 true,仅删除 setBidiEnabled(true) 调用无法关闭 BiDi。

修复方案

在 src/views/termwidget.cpp:180 对 ug_CN/bo_CN 显式调用 setBidiEnabled(false),使 RTL 文本走 LTR 强制路径(LTR_OVERRIDE_CHAR(U+202D) + AlignBottom),字符位置与 cell 网格对齐。与 analysis-report.md 第十节症状层补丁方案一致,无偏离。

改动安全评估

代码安全评估

  • 风险等级: 中风险
  • 反转 commit fdcad090(2021-03-16)引入的设计决策(为维语/藏语启用 BiDi 以获得 RTL 视觉阅读顺序),该反转由 BugFix-leader-2.0 显式批准。
  • setBidiEnabled 仅在 TermWidget 构造函数中调用一次;change-safety-raw.json 引用为空(reference_count: 0),无其他调用者受影响。

业务影响范围

仅影响维语(ug_CN)和藏语(bo_CN)终端渲染路径——这些语言环境的文本将按逻辑顺序(LTR)显示而非 RTL 视觉顺序。其他语言环境(zh_CN、en_US 等)完全不受影响。用户场景:在维语/藏语环境下运行 uos-activator-cmd -q 或任何产生混合 RTL/LTR 输出的命令。

验证建议

在 ug_CN 环境下测试 uos-activator-cmd -q 输出对齐;验证 bo_CN 终端输出对齐;确认 zh_CN/en_US 无回归。

Summary by Sourcery

Bug Fixes:

  • Prevent terminal text misalignment for mixed RTL/LTR output in Uyghur and Tibetan locales by disabling BiDi rendering.

1. Root cause: BiDi rendering reorders RTL/LTR mixed text visually,
   but reordered glyph positions misalign with terminal fixed-width
   cell grid, causing display misalignment in ug_CN/bo_CN
2. Fix: explicitly call setBidiEnabled(false) for ug_CN/bo_CN to
   force LTR path (LTR_OVERRIDE_CHAR + AlignBottom); TerminalDisplay
   defaults _bidiEnabled(true), so removing the call is insufficient
3. Impact: only ug_CN/bo_CN affected; other locales unchanged.
   Uyghur/Tibetan text shows in logical order (LTR) not RTL visual

Log: fix terminal display misalignment in Uyghur/Tibetan environment

Influence:
1. Test uos-activator-cmd -q output alignment in ug_CN locale
2. Test terminal output alignment in bo_CN locale
3. Verify no regression in zh_CN and en_US locales

fix: 禁用维语藏语 BiDi 渲染修复显示错位

1. 根因:BiDi 渲染对 RTL/LTR 混合文本做视觉重排,重排后字符位置
   与终端固定宽度 cell 网格不对应,导致 ug_CN/bo_CN 显示错位
2. 方案:对 ug_CN/bo_CN 显式 setBidiEnabled(false) 走 LTR 强制路径
   (LTR_OVERRIDE_CHAR + AlignBottom);TerminalDisplay 默认
   _bidiEnabled(true),仅删除调用无法关闭 BiDi
3. 影响:仅影响 ug_CN/bo_CN,其他语言不受影响。维语/藏语按逻辑
   顺序(LTR)显示而非 RTL 视觉顺序

Log: 修复维语/藏语环境下终端显示错位问题

Influence:
1. 测试维语环境下 uos-activator-cmd -q 输出对齐
2. 测试藏语环境下终端输出对齐
3. 验证中文/英文环境无回归

PMS: BUG-379531
@pengfeixx
pengfeixx marked this pull request as draft November 6, 2026 22:06
@sourcery-ai

sourcery-ai Bot commented Nov 6, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Disable BiDi rendering for Uyghur and Tibetan locales to keep terminal text aligned with the fixed-width cell grid.

  • src/views/termwidget.cpp L180-181

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@deepin-bot

deepin-bot Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.5.42
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #594

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant