Skip to content

fix: load pending tab when focus file missing - #677

Open
pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/bug/4d62862aa47f
Open

pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/bug/4d62862aa47f

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

fix: load pending tab when focus file missing

  1. When focus tab file is deleted or moved, recoverFile skips it
  2. Remaining pending tab at index 0 is never loaded
  3. activeTab(0) setCurrentIndex(0) does not trigger currentChanged
  4. Add explicit loadPendingTab call before activeTab(0) in fallback

Log: Fix editor unable to edit after restart when focus file deleted

Influence:

  1. Test opening 2 files, delete one, restart editor, verify editable
  2. Test opening 3 files, delete focus file, restart, verify all editable
  3. Test normal restart with existing files still works correctly

fix: 焦点文件缺失时加载待加载标签页

  1. 焦点标签页文件被删除或移动时,recoverFile 跳过该文件
  2. 剩余待加载标签页位于索引0,永远不会被加载
  3. activeTab(0) 的 setCurrentIndex(0) 不会触发 currentChanged 信号
  4. 在兜底分支的 activeTab(0) 前增加显式 loadPendingTab 调用

Log: 修复焦点文件被删除后重启编辑器无法编辑的问题

Influence:

  1. 测试打开2个文件,删除其中一个,重启编辑器,验证可编辑
  2. 测试打开3个文件,删除焦点文件,重启,验证所有标签页可编辑
  3. 测试正常重启已有文件场景仍然正常

PMS: BUG-376141

Summary by Sourcery

Bug Fixes:

  • Ensure the first pending tab is explicitly loaded when the focused file is unavailable during editor recovery, restoring editability after restart.

1. When focus tab file is deleted or moved, recoverFile skips it
2. Remaining pending tab at index 0 is never loaded
3. activeTab(0) setCurrentIndex(0) does not trigger currentChanged
4. Add explicit loadPendingTab call before activeTab(0) in fallback

Log: Fix editor unable to edit after restart when focus file deleted

Influence:
1. Test opening 2 files, delete one, restart editor, verify editable
2. Test opening 3 files, delete focus file, restart, verify all editable
3. Test normal restart with existing files still works correctly

fix: 焦点文件缺失时加载待加载标签页

1. 焦点标签页文件被删除或移动时,recoverFile 跳过该文件
2. 剩余待加载标签页位于索引0,永远不会被加载
3. activeTab(0) 的 setCurrentIndex(0) 不会触发 currentChanged 信号
4. 在兜底分支的 activeTab(0) 前增加显式 loadPendingTab 调用

Log: 修复焦点文件被删除后重启编辑器无法编辑的问题

Influence:
1. 测试打开2个文件,删除其中一个,重启编辑器,验证可编辑
2. 测试打开3个文件,删除焦点文件,重启,验证所有标签页可编辑
3. 测试正常重启已有文件场景仍然正常

PMS: BUG-376141
@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 20, 2026

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

Reviewer's Guide

Fixes editor recovery when the focused file was deleted or moved by explicitly loading a remaining pending tab at index 0, avoiding reliance on a non-emitted currentChanged signal while preserving normal tab activation behavior.

Sequence diagram for recovery when the focused file is missing

sequenceDiagram
    participant StartManager
    participant Window
    participant Tabbar

    StartManager->>Tabbar: count()
    StartManager->>Tabbar: fileAt(0)
    StartManager->>Window: isPendingTab(firstFile)
    alt first tab is pending
        StartManager->>Window: loadPendingTab(firstFile)
    end
    StartManager->>Window: activeTab(0)
    Window->>Tabbar: setCurrentIndex(0)
    Note over Window,Tabbar: currentChanged is not emitted when index is already 0
Loading

File-Level Changes

Change Details Files
Explicitly loads the first pending tab before activating the fallback tab when the focused file cannot be recovered.
  • Retrieves the first tab's file path in the no-focus fallback branch.
  • Checks whether the tab is pending and loads it explicitly before calling activeTab(0).
src/startmanager.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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/startmanager.cpp" line_range="513-515" />
<code_context>
+        // 当仅剩 pending 标签页时,currentIndex 可能已被 addPendingTab 隐式设为 0,
+        // activeTab(0) 内部的 setCurrentIndex(0) 不会触发 currentChanged 信号,
+        // 导致 pending 标签页永远不被加载。此处显式加载第一个 pending 标签页。
+        QString firstFile = window->getTabbar()->fileAt(0);
+        if (window->isPendingTab(firstFile)) {
+            window->loadPendingTab(firstFile);
+        }
         window->activeTab(0);
</code_context>
<issue_to_address>
**Earlier windows stay unloaded**

When recovery spans multiple windows and the saved focus-file record is skipped, `recoverFile` calls `loadPendingTab` only on the final `window`. Earlier windows have already selected their first pending tab while signals are blocked, so `handleCurrentChanged` does not load it; those windows remain without an editor until the user switches tabs.

Load the first pending tab in every recovered window, not only the final `window`.
</issue_to_address>

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

Comment thread src/startmanager.cpp
Comment on lines +513 to +515
QString firstFile = window->getTabbar()->fileAt(0);
if (window->isPendingTab(firstFile)) {
window->loadPendingTab(firstFile);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Earlier windows stay unloaded

When recovery spans multiple windows and the saved focus-file record is skipped, recoverFile calls loadPendingTab only on the final window. Earlier windows have already selected their first pending tab while signals are blocked, so handleCurrentChanged does not load it; those windows remain without an editor until the user switches tabs.

Load the first pending tab in every recovered window, not only the final window.

Prompt for AI agents
In `src/startmanager.cpp` at lines 513-515:

**Earlier windows stay unloaded**

When recovery spans multiple windows and the saved focus-file record is skipped, `recoverFile` calls `loadPendingTab` only on the final `window`. Earlier windows have already selected their first pending tab while signals are blocked, so `handleCurrentChanged` does not load it; those windows remain without an editor until the user switches tabs.

Load the first pending tab in every recovered window, not only the final `window`.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复了当焦点文件缺失且仅剩 pending 标签页时,pending 标签页无法被加载的问题。 新增逻辑在调用 activeTab(0) 之前显式判断并加载 pending 标签页,弥补了 setCurrentIndex(0) 不触发 currentChanged 信号的缺陷。代码语法正确、逻辑清晰,注释详尽地解释了修复原因, 无性能问题,无安全漏洞。整体为一个高质量的 bug 修复。

🔍 详细分析

1. 语法逻辑 ✅

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

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

建议: ['建议:loadPendingTab(firstFile) 调用后仍执行 activeTab(0),若 loadPendingTab 内部 会改变标签页数量或顺序,可确认 activeTab(0) 仍指向预期标签页,避免潜在的双重操作。 当前实现合理,此为防御性建议。']


2. 代码质量 ✅

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

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

建议: []


3. 代码性能 ✅

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

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

建议: []


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例

// 当前实现已为正确的修复方式,无需修改。完整上下文如下:
} else if (recFilesSum > 0 && window->getTabbar()->count() > 0) {
    // 焦点标签页文件不存在或无焦点记录,加载第一个可用标签页
    qDebug() << "No focus tab available, loading first tab";
    // 当仅剩 pending 标签页时,currentIndex 可能已被 addPendingTab 隐式设为 0,
    // activeTab(0) 内部的 setCurrentIndex(0) 不会触发 currentChanged 信号,
    // 导致 pending 标签页永远不被加载。此处显式加载第一个 pending 标签页。
    QString firstFile = window->getTabbar()->fileAt(0);
    if (window->isPendingTab(firstFile)) {
        window->loadPendingTab(firstFile);
    }
    window->activeTab(0);
}

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

@deepin-bot

deepin-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.6.8
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #678

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