fix(restore): restore last active tab and scroll position - #345
Conversation
Merge restored tabs with newly opened files preserving tab order, restore the previously active tab by file path, and add scroll position restore logging/timing. Flush bookmarks on save paths. 合并恢复标签页与新打开文件并保持顺序,按文件路径恢复上次激活 标签页,补充滚动位置恢复日志与时序处理,并在保存路径刷盘书签。 Log: 恢复上次激活标签页与滚动位置 PMS: BUG-390571 Influence: 重开应用后恢复上次激活的标签页和阅读位置,体验更连贯。
Reviewer's GuideRestores the previous active tab by path while preserving tab order, delays and instruments scroll-position restoration until layout is available, and strengthens bookmark, annotation, and tab-group persistence with autosave and disk flushing. Sequence diagram for restoring tabs and the active filesequenceDiagram
participant App as Application
participant DB as Database
participant MainWindow
participant CentralDocPage
participant DocTabBar
App->>DB: readTabGroup(0, savedActiveIndex)
App->>App: Merge restored files with new files
App->>MainWindow: createWindow(arguments)
App->>MainWindow: setInitialActiveFile(initialActiveFile)
MainWindow->>CentralDocPage: setActiveTabByFilePath(filePath)
CentralDocPage->>DocTabBar: setPendingActiveFile(filePath)
CentralDocPage->>DocTabBar: indexOfFilePath(filePath)
DocTabBar-->>CentralDocPage: tab index
CentralDocPage->>DocTabBar: setCurrentIndex(index)
DocTabBar-->>CentralDocPage: currentChanged
Sequence diagram for delayed scroll-position restorationsequenceDiagram
participant DocSheet
participant SheetBrowser
participant Layout as Layout and Event Loop
participant ScrollBar
DocSheet->>DocSheet: onOpened(error)
DocSheet->>SheetBrowser: init(operation, bookmarks)
DocSheet->>Layout: singleShot(kRestoreScrollDelayMs)
Layout->>DocSheet: restore timer fires
DocSheet->>SheetBrowser: restoreScrollPosition(scrollPosition)
SheetBrowser->>ScrollBar: minimum(), maximum(), value()
alt scroll range is ready
SheetBrowser->>ScrollBar: setValue(restored value)
else range not ready
SheetBrowser-->>DocSheet: Skip restoration
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题:
建议: 代码逻辑整体正确,边界条件处理完善(空指针检查、索引边界检查、空字符串处理)。main.cpp 中的标签页合并逻辑和激活文件选择逻辑考虑了用户指定文件和历史恢复两种场景,设计合理。CentralDocPage::setActiveTabByFilePath() 正确处理了索引不同和索引相同两种场景,使用 QPointer 确保指针安全。 2. 代码质量 ✅评价: 良好 ✅ 通过 潜在问题:
建议: 注释质量优秀,新增方法均有 Doxygen 风格注释说明用途和参数。关键逻辑(如 3 秒定时器选择原因、不在 UI 回调中直接 save 的原因)有清晰的行内注释。调试日志使用 qCDebug/qCInfo 分类输出,符合日志规范,且与 commit 目的(补充滚动位置恢复日志)一致。建议提取重复的书签/文档保存逻辑为独立方法。 3. 代码性能 ✅评价: 良好 ✅ 通过 潜在问题:
建议: main.cpp 中使用 QSet 进行文件去重查找,时间复杂度 O(1),性能良好。注释变化时使用 3 秒短定时器替代立即保存,避免 PDF 重写 + fsync 导致的 UI 卡顿,是合理的性能优化。onBrowserOperaAnnotation 中明确注释了不在 UI 回调中直接 save 的性能原因。setBookMark 中的 flushToDisk 对单次操作合理,批量场景可考虑延时合并。 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 代码不涉及用户直接输入处理,文件路径来源于应用自身保存的状态。无 SQL 注入、命令注入、路径遍历等安全风险。无硬编码密钥或敏感信息泄露。使用 Qt 安全的字符串和容器类,无缓冲区溢出风险。QPointer 的使用确保了指针安全。 💡 改进建议代码示例// 建议提取重复的书签保存逻辑为独立方法
void DocSheet::saveBookmarksToDisk()
{
Database::instance()->saveBookmarks(filePath(), m_bookmarks);
Database::instance()->flushToDisk();
m_bookmarkChanged = false;
}
// 建议提取重复的文档保存逻辑为独立方法
void DocSheet::saveDocumentToDisk()
{
if (m_documentChanged && m_renderer) {
if (m_renderer->save()) {
m_documentChanged = false;
m_sidebar->changeResetModelData();
} else {
qCWarning(appLog) << "Failed to save document for:" << m_filePath;
}
}
}
// 在 setBookMark/setBookMarks/setAlive/onAutoSave 中调用
// 替换重复的保存代码:
// saveBookmarksToDisk();
// saveDocumentToDisk();本报告由 AI 代码审查工具自动生成 |
|
/merge |
Merge restored tabs with newly opened files preserving tab order, restore the previously active tab by file path, and add scroll position restore logging/timing. Flush bookmarks on save paths.
合并恢复标签页与新打开文件并保持顺序,按文件路径恢复上次激活
标签页,补充滚动位置恢复日志与时序处理,并在保存路径刷盘书签。
Log: 恢复上次激活标签页与滚动位置
PMS: BUG-390571
Influence: 重开应用后恢复上次激活的标签页和阅读位置,体验更连贯。
Summary by Sourcery
Restore the last active tab and reading position while preserving tab order and reliably flushing document state to disk.
New Features:
Bug Fixes:
Enhancements:
Chores: