Skip to content

fix: prevent white flash on dark theme read-only view switch - #709

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

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

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

When switching from live preview to read-only view in dark theme, a white flash appeared because three layers of background color protection were missing. The m_pReadPage QWidget container had no setAutoFillBackground/setPalette call in OnThemeChangeSlot (editwrapper.cpp), MarkdownView (QWebEngineView subclass) never called page()->setBackgroundColor() so Chromium rendered a default white background (markdownview.cpp), and theme.css --bg CSS variable defaults to #ffffff with the dark value injected asynchronously via JS bridge — leaving a gap during the switch transition.

Fix Approach

Added m_pReadPage palette setting in OnThemeChangeSlot after the existing m_pBottomBar->setPalette() call, consistent with the existing pattern. Added page()->setBackgroundColor(Qt::white) in MarkdownView::init() before load() as the default, and page()->setBackgroundColor(bgColor) in applyTheme() to synchronously set the Chromium render layer background from the theme map's editor-colors.background-color — closing the async JS bridge gap.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Changes are purely additive visual API calls (setAutoFillBackground, setPalette, page()->setBackgroundColor), no function signature changes, no control flow modifications, no caller impact
  • No historical fixes reverted — target lines are not products of prior bug fixes; all 5 related PMS bugs (379439, 378319, 378209, 380705, 378157) are in unrelated code paths

Business Impact Scope

  • Markdown read-only view — dark theme live preview → read-only view switch display
  • Affected callers: EditWrapper::OnThemeChangeSlot(), MarkdownView::init(), MarkdownView::applyTheme()
  • Users opening Markdown files in dark theme and switching to read-only view will no longer see a white flash

Verification Suggestion

Focus regression testing on dark theme Markdown view switching (live preview ↔ read-only) and theme toggle (dark ↔ light) to confirm background color correctness and no white flash.


根因分析

深色主题下从实时预览切换到只读视图时出现白色闪烁,原因是三层背景色防护均缺失。m_pReadPage QWidget 容器在 OnThemeChangeSlot 中未设置 setAutoFillBackground/setPalette(editwrapper.cpp);MarkdownView(QWebEngineView 子类)全代码无 page()->setBackgroundColor() 调用,Chromium 渲染默认白底(markdownview.cpp);theme.css 的 --bg CSS 变量默认 #ffffff,深色值经异步 JS bridge 注入,切换瞬间 CSS 变量尚未更新。

修复方案

在 OnThemeChangeSlot 中已有的 m_pBottomBar->setPalette() 之后新增 m_pReadPage 的 palette 设置,与现有模式一致。在 MarkdownView::init() 的 load() 之前添加 page()->setBackgroundColor(Qt::white) 作为默认值,在 applyTheme() 中根据主题色同步设置 Chromium 渲染层背景色,消除异步 JS bridge 注入前的间隙。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 改动均为纯补充性视觉 API 调用(setAutoFillBackground、setPalette、page()->setBackgroundColor),无函数签名变更、无控制流修改、无调用者影响
  • 未撤销任何历史修复——目标行非历史修复产物;5 个关联 PMS bug(379439、378319、378209、380705、378157)均在不相关代码路径中,无回归风险

业务影响范围

  • Markdown 只读视图 — 深色主题下实时预览 → 只读视图切换显示
  • 涉及调用者:EditWrapper::OnThemeChangeSlot()、MarkdownView::init()、MarkdownView::applyTheme()
  • 用户在深色主题下打开 Markdown 文件并切换到只读视图时不再出现白色闪烁

验证建议

回归测试重点:深色主题 Markdown 视图切换(实时预览 ↔ 只读)及主题切换(深色 ↔ 浅色),确认背景色正确且无白色闪烁。

Summary by Sourcery

Bug Fixes:

  • Prevent white flashes when switching to the Markdown read-only view under dark themes by synchronizing background colors across the container and web rendering layers.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pengfeixx

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pengfeixx
pengfeixx marked this pull request as draft November 2, 2026 13:40
@sourcery-ai

sourcery-ai Bot commented Nov 2, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR prevents white flashes when switching Markdown from live preview to read-only mode in dark theme by synchronizing backgrounds at the QWidget, Chromium page, and theme-color application layers. Review regression coverage should focus on live preview/read-only transitions and dark/light theme changes.

Sequence diagram for synchronized Markdown read-only background theme

sequenceDiagram
    participant EditWrapper
    participant ReadPage as ReadPage QWidget
    participant MarkdownView
    participant Chromium as Chromium Page
    participant JSBridge as Theme JS Bridge

    EditWrapper->>ReadPage: setAutoFillBackground(true)
    EditWrapper->>ReadPage: setPalette(readPalette)
    MarkdownView->>Chromium: setBackgroundColor(Qt.white)
    EditWrapper->>MarkdownView: applyTheme(themeMap)
    MarkdownView->>Chromium: setBackgroundColor(bgColor)
    MarkdownView->>JSBridge: applyTheme(themeMap)
    JSBridge-->>MarkdownView: CSS --bg updated
Loading

File-Level Changes

Change Details Files
Adds synchronous background-color coverage across the read-only view container and Chromium rendering layer to eliminate dark-theme transition flashes.
  • Applies the themed window palette and enables background filling on the read-only QWidget container.
  • Initializes the web page background to white before loading content.
  • Updates the Chromium page background immediately from the themed editor background color, independently of asynchronous CSS bridge injection.
src/editor/editwrapper.cpp
src/editor/markdown/markdownview.cpp

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 ✨

@pengfeixx
pengfeixx marked this pull request as ready for review November 3, 2026 05:47
1. Root cause: m_pReadPage container had no palette set in
   OnThemeChangeSlot, MarkdownView never called
   page()->setBackgroundColor(), and theme.css --bg defaults to
   #ffffff with dark value injected asynchronously via JS bridge
2. Fix: set m_pReadPage palette with background color in
   OnThemeChangeSlot, call page()->setBackgroundColor(Qt::white) in
   MarkdownView::init() as default, and page()->setBackgroundColor
   (bgColor) in applyTheme() to sync Chromium render layer
3. Impact: dark theme read-only view switch no longer flashes white;
   light theme behavior unchanged

Log: fix white flash when switching to read-only view in dark theme

Influence:
1. Test dark theme md file switch from live preview to read-only view
2. Test light theme same operation for no regression
3. Test theme switch (dark/light) updates read-only view background

fix: 修复深色主题下只读视图切换白色闪烁

1. 根因:m_pReadPage 容器在 OnThemeChangeSlot 中未设置 palette,
   MarkdownView 从未调用 page()->setBackgroundColor(),theme.css
   的 --bg 默认 #ffffff 且深色值经 JS bridge 异步注入
2. 方案:在 OnThemeChangeSlot 中为 m_pReadPage 设置背景色 palette,
   在 MarkdownView::init() 调用 page()->setBackgroundColor(Qt::white)
   设默认值,在 applyTheme() 同步 Chromium 渲染层背景色
3. 影响:深色主题下只读视图切换不再白色闪烁,浅色主题行为不变

Log: 修复深色主题下切换只读视图白色闪烁问题

Influence:
1. 测试深色主题下 md 文件从实时预览切换到只读视图无闪烁
2. 测试浅色主题下同样操作无回归
3. 测试主题切换(深色/浅色)时只读视图背景色正确更新

PMS: BUG-378219
@pengfeixx
pengfeixx force-pushed the agent/agent/1bd64403052d branch from 61f45a1 to 9e3548d Compare November 3, 2026 07:06
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复深色主题切换时只读视图白色闪烁问题,代码变更简洁精准,语法正确逻辑清晰,无安全漏洞,无性能问题,注释完整,代码质量优秀。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 无改进建议


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 无改进建议


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 无改进建议


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 无改进建议


💡 改进建议代码示例

// 当前代码已足够完善,无需修改示例。 // editwrapper.cpp - 已有空指针检查和正确的 palette 设置 // markdownview.cpp - 已有 isValid() 校验和合理的默认值设置

本报告由 AI 代码审查工具自动生成

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.

2 participants