Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/startmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void StartManager::autoBackupFile()
qCDebug(appLog) << "Exit autoBackupFile";
}

int StartManager::recoverFile(Window *window)
int StartManager::recoverFile(Window *window, const QStringList &explicitFiles)
{
qCDebug(appLog) << "Enter recoverFile";

Expand Down Expand Up @@ -420,6 +420,15 @@ int StartManager::recoverFile(Window *window)
}
}

// 跳过显式请求打开的文件的备份记录,避免会话恢复与显式打开之间路径去重失败
if (!explicitFiles.isEmpty() && !localPath.isEmpty()) {
QString resolvedLocal = Utils::getFilePath(localPath);
if (explicitFiles.contains(resolvedLocal)) {
qCDebug(appLog) << "Skipping backup for explicitly opened file:" << localPath;
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 Critical · Unsaved recovery edits disappear

When an explicitly opened file has a modified recovery backup, recoverFile skips the backup, so openFilesInTab opens the on-disk contents instead or, if the file is unreadable, leaves no tab with the valid backup. A later autoBackupFile can overwrite the saved session record with the opened file's current contents.

Preserve and restore the modified backup for explicitly opened files, including when opening the on-disk file fails.

Also at src/startmanager.cpp:429.

Prompt for AI agents
In `src/startmanager.cpp` at line 428:

**Unsaved recovery edits disappear**

When an explicitly opened file has a modified recovery backup, `recoverFile` skips the backup, so `openFilesInTab` opens the on-disk contents instead or, if the file is unreadable, leaves no tab with the valid backup. A later `autoBackupFile` can overwrite the saved session record with the opened file's current contents.

Preserve and restore the modified backup for explicitly opened files, including when opening the on-disk file fails.

Also at `src/startmanager.cpp:429`.

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 · Restored tabs lose window separation

When all saved records in the first window match explicitly opened files and a later saved window has records to restore, recoverFile skips the first window's records before updating windowIndex, so the first later-window record initializes the index without creating a window and its tabs are added to the supplied window alongside the explicitly opened files.

Update the saved window index and create the corresponding window before skipping an explicitly opened record.

Also at src/startmanager.cpp:429.

Prompt for AI agents
In `src/startmanager.cpp` at line 428:

**Restored tabs lose window separation**

When all saved records in the first window match explicitly opened files and a later saved window has records to restore, `recoverFile` skips the first window's records before updating `windowIndex`, so the first later-window record initializes the index without creating a window and its tabs are added to the supplied window alongside the explicitly opened files.

Update the saved window index and create the corresponding window before skipping an explicitly opened record.

Also at `src/startmanager.cpp:429`.

}
}

// 确定实际打开路径和显示名称
QString openPath;
QString displayName;
Expand Down Expand Up @@ -639,7 +648,11 @@ void StartManager::openFilesInTab(QStringList files)
// 以 window 为 context:窗口在延时期间被销毁则不触发,避免悬空调用
QTimer::singleShot(50, window, [ = ] {
qCDebug(appLog) << "Delayed file opening for:" << resolvedFile;
recoverFile(window);
QStringList resolvedFiles;
for (const QString &f : files) {
resolvedFiles << Utils::getFilePath(f);
}
recoverFile(window, resolvedFiles);

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 · Recovery opens duplicate tabs

When a second openFilesInTab request arrives during the first request's 50 ms delay and includes a file with a saved backup, openFilesInTab opens the second request's file immediately, but the first request's delayed recovery passes only its own file list to recoverFile, which restores the second file's backup as another tab.

Pass recovery the combined list of files opened by requests received before the delayed recovery runs.

Prompt for AI agents
In `src/startmanager.cpp` at line 655:

**Recovery opens duplicate tabs**

When a second `openFilesInTab` request arrives during the first request's 50 ms delay and includes a file with a saved backup, `openFilesInTab` opens the second request's file immediately, but the first request's delayed recovery passes only its own file list to `recoverFile`, which restores the second file's backup as another tab.

Pass recovery the combined list of files opened by requests received before the delayed recovery runs.

window->addTab(resolvedFile);
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/startmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ class StartManager : public QObject
/**
* @brief recoverFile 备份恢复
* @param window 从哪个窗口进行恢复
* @param explicitFiles 显式请求打开的文件路径列表,恢复时跳过这些文件的备份记录
* @return 恢复完成的文件数量
*/
int recoverFile(Window *window);
int recoverFile(Window *window, const QStringList &explicitFiles = QStringList());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 Critical · Test target no longer compiles

When the test target is compiled, recoverFile has a two-parameter member-function type despite its default argument, so the existing one-parameter static_cast stubs in test_startmanager fail and the test target does not build.

Preserve the one-parameter overload and add a separate overload that accepts the explicit-file list.

Also at src/startmanager.cpp:330, src/startmanager.h:64.

Prompt for AI agents
In `src/startmanager.h` at line 63:

**Test target no longer compiles**

When the test target is compiled, `recoverFile` has a two-parameter member-function type despite its default argument, so the existing one-parameter `static_cast` stubs in `test_startmanager` fail and the test target does not build.

Preserve the one-parameter overload and add a separate overload that accepts the explicit-file list.

Also at `src/startmanager.cpp:330`, `src/startmanager.h:64`.


/**
* @brief analyzeBookmakeInfo 解析书签信息
Expand Down
Loading