From 893e25fafcc2a3d2ce955ec7a5b1134197a261e3 Mon Sep 17 00:00:00 2001 From: xiepengfei Date: Tue, 20 Oct 2026 22:21:24 +0800 Subject: [PATCH] fix: load pending tab when focus file missing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/startmanager.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/startmanager.cpp b/src/startmanager.cpp index 232dc5d3..6353f0d6 100644 --- a/src/startmanager.cpp +++ b/src/startmanager.cpp @@ -507,6 +507,13 @@ int StartManager::recoverFile(Window *window) } 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); }