Skip to content

fix: restore find widget visibility on tab switch - #427

Open
pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/pms-bug-bot/e43b4d339d1f
Open

pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/pms-bug-bot/e43b4d339d1f

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

fix: restore find widget visibility on tab switch

  1. Root cause: commit 78deba7 introduced deleteLater() +
    nullptr in hideFindWidget(), destroying FindWidget on tab
    switch; restoreSavedViewState() lacked findWidgetVisible
    field so search box never reappeared
  2. Fix: add findWidgetVisible to SheetOperation, save it in
    saveCurrentViewState(), restore via handlePrepareSearch() in
    restoreSavedViewState(); change hideFindWidget() to hide()
    only, removing deleteLater() and nullptr assignment
  3. Impact: FindWidget survives tab switches preserving search
    text; stopSearch() still called before hide prevents search
    cross-contamination regression (bug 376317)

Log: fix search box disappearing after switching tabs in multi-tab mode

Influence:

  1. Test search box visibility after switching between tabs
  2. Verify search text is preserved after tab switch
  3. Verify no search cross-contamination between tabs

fix: 修复切换标签页后搜索框不显示的问题

  1. 根因:commit 78deba7 在 hideFindWidget() 中引入 deleteLater()
    和 nullptr 赋值,切换标签页时销毁了 FindWidget;
    restoreSavedViewState() 缺少 findWidgetVisible 字段,切回时
    无法恢复搜索框显示
  2. 方案:SheetOperation 添加 findWidgetVisible 字段,
    saveCurrentViewState() 保存搜索框可见性,restoreSavedViewState()
    通过 handlePrepareSearch() 恢复;hideFindWidget() 改为仅 hide()
    移除 deleteLater() 和 nullptr 赋值
  3. 影响:FindWidget 在标签页切换后存活并保留搜索文本;
    stopSearch() 仍在 hide 前调用,防止搜索串档回归(bug 376317)

Log: 修复多标签页模式下切换标签页后搜索框消失的问题

Influence:

  1. 测试切换标签页后搜索框可见性恢复
  2. 验证切换标签页后搜索文本保留
  3. 验证标签页间无搜索串档回归

PMS: BUG-379133

Summary by Sourcery

Preserve find-widget state across document tab switches without allowing searches to leak between tabs.

Bug Fixes:

  • Restore find-widget visibility and search text when switching between document tabs.
  • Prevent the find widget from being destroyed during tab switches while continuing to isolate searches between tabs.

Enhancements:

  • Persist find-widget visibility as part of each sheet's view state and restore it when returning to a tab.

1. Root cause: commit 78deba7 introduced deleteLater() +
   nullptr in hideFindWidget(), destroying FindWidget on tab
   switch; restoreSavedViewState() lacked findWidgetVisible
   field so search box never reappeared
2. Fix: add findWidgetVisible to SheetOperation, save it in
   saveCurrentViewState(), restore via handlePrepareSearch() in
   restoreSavedViewState(); change hideFindWidget() to hide()
   only, removing deleteLater() and nullptr assignment
3. Impact: FindWidget survives tab switches preserving search
   text; stopSearch() still called before hide prevents search
   cross-contamination regression (bug 376317)

Log: fix search box disappearing after switching tabs in multi-tab mode

Influence:
1. Test search box visibility after switching between tabs
2. Verify search text is preserved after tab switch
3. Verify no search cross-contamination between tabs

fix: 修复切换标签页后搜索框不显示的问题

1. 根因:commit 78deba7 在 hideFindWidget() 中引入 deleteLater()
   和 nullptr 赋值,切换标签页时销毁了 FindWidget;
   restoreSavedViewState() 缺少 findWidgetVisible 字段,切回时
   无法恢复搜索框显示
2. 方案:SheetOperation 添加 findWidgetVisible 字段,
   saveCurrentViewState() 保存搜索框可见性,restoreSavedViewState()
   通过 handlePrepareSearch() 恢复;hideFindWidget() 改为仅 hide()
   移除 deleteLater() 和 nullptr 赋值
3. 影响:FindWidget 在标签页切换后存活并保留搜索文本;
   stopSearch() 仍在 hide 前调用,防止搜索串档回归(bug 376317)

Log: 修复多标签页模式下切换标签页后搜索框消失的问题

Influence:
1. 测试切换标签页后搜索框可见性恢复
2. 验证切换标签页后搜索文本保留
3. 验证标签页间无搜索串档回归

PMS: BUG-379133
@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

@sourcery-ai

sourcery-ai Bot commented Oct 21, 2026

Copy link
Copy Markdown

Reviewer's Guide

The fix keeps FindWidget alive across tab switches, records its visibility in each sheet’s saved view state before hiding it, and restores the search UI when returning to that tab while preserving the existing stop-search isolation behavior.

Sequence diagram for restoring find widget visibility on tab switch

sequenceDiagram
    participant CentralDocPage
    participant PreviousSheet
    participant DocSheet
    participant SheetBrowser
    participant FindWidget
    participant CurrentSheet

    CentralDocPage->>PreviousSheet: saveCurrentViewState()
    PreviousSheet->>SheetBrowser: isFindWidgetVisible()
    SheetBrowser->>FindWidget: isVisible()
    FindWidget-->>SheetBrowser: visibility
    SheetBrowser-->>PreviousSheet: findWidgetVisible
    PreviousSheet->>PreviousSheet: closeFindWidget()
    PreviousSheet->>SheetBrowser: hideFindWidget()
    SheetBrowser->>FindWidget: hide()
    CentralDocPage->>CurrentSheet: restoreSavedViewState()
    CurrentSheet->>SheetBrowser: handlePrepareSearch()
    SheetBrowser-->>CurrentSheet: FindWidget remains visible
Loading

File-Level Changes

Change Details Files
Preserve the find widget instance and restore its visibility as part of per-tab view state.
  • Changed hiding to retain the widget and its search text instead of scheduling destruction.
  • Added a visibility query for the find widget.
  • Added find-widget visibility to sheet state and captured it before closing the widget during tab changes.
  • Recreated the visible search state through the existing search-preparation path when restoring a sheet.
reader/browser/SheetBrowser.cpp
reader/browser/SheetBrowser.h
reader/uiframe/CentralDocPage.cpp
reader/uiframe/DocSheet.cpp
reader/uiframe/DocSheet.h
Maintain tab isolation while restoring search UI state.
  • Kept the existing close/stop-search behavior after saving the outgoing sheet state to prevent search activity from leaking between tabs.
reader/uiframe/CentralDocPage.cpp
reader/uiframe/DocSheet.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 ✨

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过(有建议)
评分详情 本次提交修复了切换标签页时搜索框可见性状态丢失的问题,核心逻辑正确、注释完善、无安全漏洞。 但存在一个逻辑缺陷:hideFindWidget() 不再销毁搜索框后,handlePrepareSearch() 中的 sizeModeChanged 信号连接会因重复调用而累积,导致多次切换标签页后 sizeModeChanged 信号会触发多次冗余的 updatePosition() 调用。建议将 connect() 移入 if (m_findWidget == nullptr) 块内或使用 Qt::UniqueConnection 避免重复连接。

🔍 详细分析

1. 语法逻辑 ❌

评价: 存在逻辑缺陷 ❌ 不通过

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

建议: ['将 handlePrepareSearch() 中的 connect() 移入 if (m_findWidget == nullptr) 块内,或使用 Qt::UniqueConnection 避免重复连接']


2. 代码质量 ✅

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

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

建议: []


3. 代码性能 ✅

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

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

建议: ['将 connect() 移入 if (m_findWidget == nullptr) 块内或使用 Qt::UniqueConnection,避免连接累积']


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例

// 修复方案:将 connect() 移入 if (m_findWidget == nullptr) 块内
// 文件:reader/browser/SheetBrowser.cpp
void SheetBrowser::handlePrepareSearch()
{
    qCDebug(appLog) << "Preparing search for file type:" << m_sheet->fileType();

    if (!Dr::supportsSearch(m_sheet->fileType())) {
        qCDebug(appLog) << "Search not supported for current file type";
        return;
    }

    if (m_findWidget == nullptr) {
        m_findWidget = new FindWidget(this->window());
        int windowY = this->mapTo(this->window(), QPoint(0, 0)).y();
        m_findWidget->setYOff(windowY);
        m_findWidget->setDocSheet(m_sheet);
        qCDebug(appLog) << "Created new FindWidget with Y offset:" << windowY;

#ifdef DTKWIDGET_CLASS_DSizeMode
        // 将 connect() 移入此块内,确保仅在创建控件时连接一次
        connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, [=](DGuiApplicationHelper::SizeMode sizeMode) {
            if(m_findWidget && m_findWidget->isVisible()){
                m_findWidget->updatePosition();
            }
        });
#endif
    }

    m_findWidget->updatePosition();
    m_findWidget->setSearchEditFocus();
    qCDebug(appLog) << "FindWidget positioned and focused";
}

本报告由 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