Repository navigation
Conversation
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideUISet the MarkdownView widget palette and enable background filling when applying a theme or handling theme changes, preventing a white surface during view-mode reparenting.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/editor/markdown/markdownview.cpp" line_range="196" />
<code_context>
- if (bgColor.isValid())
+ if (bgColor.isValid()) {
page()->setBackgroundColor(bgColor);
+ m_lastBgColor = bgColor;
+ }
m_lastThemeJson = json;
</code_context>
<issue_to_address>
**Old background returns after theme change**
When a valid theme is followed by a theme with a missing or invalid background, `applyTheme()` leaves `m_lastBgColor` unchanged while marking the new theme present, so `setMode()` reapplies the previous color even though the current serialized theme falls back to white; the page background no longer matches the theme.
Clear or update `m_lastBgColor` to the current theme’s fallback when `applyTheme()` receives no valid background.
Also at `src/editor/markdown/markdownview.cpp:179-180`, `src/editor/markdown/markdownview.cpp:197`.
</issue_to_address>
### Comment 2
<location path="src/editor/markdown/markdownview.cpp" line_range="178-180" />
<code_context>
void MarkdownView::setMode(int mode)
{
+ // 切换模式时恢复最近一次主题背景色,防止 Chromium 渲染层回退到默认白色
+ if (m_hasTheme && m_lastBgColor.isValid())
+ page()->setBackgroundColor(m_lastBgColor);
emit m_bridge->setModeRequested(mode == Editable);
}
</code_context>
<issue_to_address>
**Dark mode still flashes white**
When `EditWrapper::setViewMode()` reparents and shows the Markdown view before `setMode()` updates its background, chromium recomposites or commits a frame during that earlier transition, before `setBackgroundColor()` runs, so the later update cannot prevent users from seeing a white flash.
Apply the theme background before reparenting and showing the view, or prevent rendering until the background has been updated.
</issue_to_address>| if (bgColor.isValid()) | ||
| if (bgColor.isValid()) { | ||
| page()->setBackgroundColor(bgColor); | ||
| m_lastBgColor = bgColor; |
There was a problem hiding this comment.
🟡 Medium · Old background returns after theme change
When a valid theme is followed by a theme with a missing or invalid background, applyTheme() leaves m_lastBgColor unchanged while marking the new theme present, so setMode() reapplies the previous color even though the current serialized theme falls back to white; the page background no longer matches the theme.
Clear or update m_lastBgColor to the current theme’s fallback when applyTheme() receives no valid background.
Also at src/editor/markdown/markdownview.cpp:179-180, src/editor/markdown/markdownview.cpp:197.
Prompt for AI agents
In `src/editor/markdown/markdownview.cpp` at line 196:
**Old background returns after theme change**
When a valid theme is followed by a theme with a missing or invalid background, `applyTheme()` leaves `m_lastBgColor` unchanged while marking the new theme present, so `setMode()` reapplies the previous color even though the current serialized theme falls back to white; the page background no longer matches the theme.
Clear or update `m_lastBgColor` to the current theme’s fallback when `applyTheme()` receives no valid background.
Also at `src/editor/markdown/markdownview.cpp:179-180`, `src/editor/markdown/markdownview.cpp:197`.| // 切换模式时恢复最近一次主题背景色,防止 Chromium 渲染层回退到默认白色 | ||
| if (m_hasTheme && m_lastBgColor.isValid()) | ||
| page()->setBackgroundColor(m_lastBgColor); |
There was a problem hiding this comment.
🟡 Medium · Dark mode still flashes white
When EditWrapper::setViewMode() reparents and shows the Markdown view before setMode() updates its background, chromium recomposites or commits a frame during that earlier transition, before setBackgroundColor() runs, so the later update cannot prevent users from seeing a white flash.
Apply the theme background before reparenting and showing the view, or prevent rendering until the background has been updated.
Prompt for AI agents
In `src/editor/markdown/markdownview.cpp` at lines 178-180:
**Dark mode still flashes white**
When `EditWrapper::setViewMode()` reparents and shows the Markdown view before `setMode()` updates its background, chromium recomposites or commits a frame during that earlier transition, before `setBackgroundColor()` runs, so the later update cannot prevent users from seeing a white flash.
Apply the theme background before reparenting and showing the view, or prevent rendering until the background has been updated.1. Root cause: commit 01856b2 set page-level background color on QWebEngineView but missed widget-level palette, causing reparent Show event to paint default white surface during view mode switch 2. Fix: add setPalette + setAutoFillBackground for m_pMarkdownView in OnThemeChangeSlot and applyTheme, mirroring existing m_pReadPage pattern 3. Impact: eliminates white flash on dark theme LivePreview to ReadView switch; no effect on light theme Log: fix white flash when switching from live preview to read-only mode under dark theme Influence: 1. Test dark theme LivePreview to ReadView switch for no white flash 2. Test light theme switch remains unaffected 3. Verify theme change correctly updates MarkdownView background fix: 为 MarkdownView 设置 widget 级 palette 防止白色闪烁 1. 根因:提交 01856b2 设置了 QWebEngineView 的 page 级背景色但遗漏 widget 级 palette,reparent 时 Show 事件绘制默认白色表面 2. 方案:在 OnThemeChangeSlot 和 applyTheme 中为 m_pMarkdownView 补全 setPalette + setAutoFillBackground,与 m_pReadPage 写法同构 3. 影响:消除深色主题下实时预览切只读模式的白色闪烁;浅色主题不受影响 Log: 修复深色主题下实时预览切换只读模式时的白色闪烁问题 Influence: 1. 测试深色主题下实时预览切换只读模式无白色闪烁 2. 测试浅色主题切换不受影响 3. 验证主题切换时 MarkdownView 背景色正确更新 PMS: BUG-378219
3f393bb to
f40b94c
Compare
Root Cause Analysis
When switching md file view mode from live preview to read-only under dark theme,
MarkdownView::setMode()only emits a signal to the JS bridge without re-applying the cached theme background color. The reparent operation (fromLiveSplittertoReadPage) triggers Chromium recomposite, which uses the default white background set ininit()(page()->setBackgroundColor(Qt::white)), causing a brief white flash (~33ms, 1 frame).Key evidence:
markdownview.cpp:176(setMode()only emits signal),markdownview.cpp:191(applyTheme()sets bg color but doesn't cache it), GIF frame analysis showing brightness jump 46.5→135.3.Fix Approach
Add
QColor m_lastBgColorprivate member toMarkdownView. CachebgColorinapplyTheme()when valid. InsetMode(), before emitting the signal, re-applym_lastBgColorviapage()->setBackgroundColor()whenm_hasTheme && m_lastBgColor.isValid(). This complements the prior partial fix01856b21without reverting any of its changes.Change Safety Assessment
Code Safety
setMode()applyTheme()was introduced by prior fix01856b21; this change preserves it and only adds cachingsetMode()was never modified since introduction (81fbb72f); no historical fix is revertedBusiness Impact Scope
Affects only the Markdown view mode switch path (live preview ↔ read-only). Users on dark theme will no longer see white flash when switching to read-only mode. Other theme/mode operations unaffected.
Verification Suggestion
Test dark theme live-preview→read-only switch for no white flash. Test light theme mode switch for no regression. Test theme change followed by mode switch.
根因分析
深色主题下从实时预览切换为只读模式时,
MarkdownView::setMode()仅向 JS bridge 发出信号,未重新应用缓存的主题背景色。reparent 操作(从LiveSplitter到ReadPage)触发 Chromium 重合成,使用init()中设置的默认白色背景,导致短暂白色闪烁(约 33ms,1 帧)。关键证据:
markdownview.cpp:176(setMode()仅发信号)、markdownview.cpp:191(applyTheme()设置背景色但未缓存)、GIF 帧分析显示亮度跳变 46.5→135.3。修复方案
在
MarkdownView中新增QColor m_lastBgColor私有成员。在applyTheme()中当颜色有效时缓存到m_lastBgColor。在setMode()中 emit 信号前,当m_hasTheme && m_lastBgColor.isValid()时通过page()->setBackgroundColor()重新应用背景色。与先前部分修复01856b21互补,不撤销其任何改动。改动安全评估
代码安全
setMode()中的条件分支applyTheme()目标行由先前修复01856b21引入;本次保留该行不变,仅新增缓存setMode()自引入(81fbb72f)以来从未被修改;不撤销任何历史修复业务影响范围
仅影响 Markdown 视图模式切换路径(实时预览↔只读)。深色主题用户切换到只读模式时不再出现白色闪烁。其他主题/模式操作不受影响。
验证建议
测试深色主题下实时预览→只读切换无白色闪烁。测试浅色主题模式切换无回归。测试主题切换后再切换视图模式。
PMS: BUG-378219
Summary by Sourcery
Prevent transient white flashes during Markdown view mode changes by consistently applying themed background colors to the view and its page.
Bug Fixes: