From 6483fcf2748b3645dd55806070ba519ff1516eba Mon Sep 17 00:00:00 2001 From: xiepengfei Date: Tue, 20 Oct 2026 22:20:11 +0800 Subject: [PATCH] fix: load pending tab in recoverFile fallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Root cause: when focus tab file is deleted/moved, recoverFile() skips it via continue, leaving only pending tabs added by addPendingTab which implicitly sets currentIndex to 0 with signals blocked 2. Fix: before calling activeTab(0), check if the first tab is still pending and explicitly call loadPendingTab() to load its content, bypassing the currentChanged signal dependency 3. Impact: fixes editor being uneditable after restart when exactly 2 files were open and the focus tab file was deleted; no behavior change for normal recovery paths Log: fix editor uneditable when focus tab file is deleted Influence: 1. Test opening 2 files, delete the focus file, restart editor 2. Verify editor content loads and is editable after restart 3. Test opening 3 files, delete focus file, restart editor 4. Verify normal file recovery still works correctly fix: recoverFile兜底分支显式加载待加载标签页 1. 根因:焦点标签页文件被删除/移动后,recoverFile() 通过 continue 跳过该标签页,仅剩 addPendingTab 添加的待加载标签页,其内部 隐式将 currentIndex 设为 0 但信号被阻塞 2. 方案:在调用 activeTab(0) 前,检查第一个标签页是否为待加载 状态,若是则显式调用 loadPendingTab() 加载内容,不依赖 currentChanged 信号触发 3. 影响:修复打开2个文件且焦点标签页文件被删除后重启编辑器 无法编辑的问题,不影响正常文件恢复路径 Log: 修复焦点标签页文件被删除后编辑器无法编辑的问题 Influence: 1. 测试打开2个文件,删除焦点文件后重启编辑器 2. 验证重启后编辑器内容正常加载且可编辑 3. 测试打开3个文件,删除焦点文件后重启编辑器 4. 验证正常文件恢复功能不受影响 PMS: BUG-376141 --- src/startmanager.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/startmanager.cpp b/src/startmanager.cpp index 232dc5d3..37495d3d 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 标签页,否则编辑区域为空且无法编辑 + QString firstFile = window->getTabbar()->fileAt(0); + if (window->isPendingTab(firstFile)) { + window->loadPendingTab(firstFile); + } window->activeTab(0); }