Skip to content

fix(reader): skip docx annotation auto-save so close prompts save-as … - #378

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:feature/fix-BUG376501
Sep 10, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:feature/fix-BUG376501

Conversation

@add-uos

@add-uos add-uos commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

…dialog

Docx files are opened through a converted temp.pdf under a random temporary directory, so annotation auto-save cannot really persist: onAutoSave wrote annotations into temp.pdf and cleared the changed flag, which made fileChanged() false on close. The save-confirmation dialog was therefore skipped and annotations were silently lost when the temporary directory was removed.

Skip the annotation save in onAutoSave for docx and keep the sheet marked as changed, so closing prompts the confirmation dialog where "Save" routes to save-as PDF. PDF/DJVU/XPS behavior is unchanged.

Log: 修复 docx 添加注释后关闭查看器不弹保存确认框导致注释静默丢失的问题
PMS: BUG-376501
Influence: docx 添加注释/高亮后关闭查看器会弹保存确认框,选"保存"可另存为 PDF 保留注释;PDF/DJVU/XPS 的自动保存行为不变。

Summary by Sourcery

Ensure DOCX annotation changes prompt for confirmation on close, allowing users to save them as PDF.

Bug Fixes:

  • Preserve the changed state for annotations added to DOCX files so closing the viewer displays the save-confirmation dialog instead of silently losing them.
  • Keep existing annotation auto-save behavior unchanged for PDF, DJVU, and XPS files.

…dialog

Docx files are opened through a converted temp.pdf under a random
temporary directory, so annotation auto-save cannot really persist:
onAutoSave wrote annotations into temp.pdf and cleared the changed
flag, which made fileChanged() false on close. The save-confirmation
dialog was therefore skipped and annotations were silently lost when
the temporary directory was removed.

Skip the annotation save in onAutoSave for docx and keep the sheet
marked as changed, so closing prompts the confirmation dialog where
"Save" routes to save-as PDF. PDF/DJVU/XPS behavior is unchanged.

Log: 修复 docx 添加注释后关闭查看器不弹保存确认框导致注释静默丢失的问题
PMS: BUG-376501
Influence: docx 添加注释/高亮后关闭查看器会弹保存确认框,选"保存"可另存为 PDF 保留注释;PDF/DJVU/XPS 的自动保存行为不变。

@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.

Sorry @add-uos, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 2 hours and 57 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 10, 2026

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

Reviewer's Guide

Updates DOCX auto-save handling to skip persistence into the temporary converted PDF and preserve the dirty state, ensuring closing prompts users to save annotations as PDF while leaving PDF/DJVU/XPS behavior unchanged.

Sequence diagram for DOCX annotation close and save confirmation

sequenceDiagram
    participant User
    participant DocSheet
    participant TempPDF
    participant SaveAsPDF

    User->>DocSheet: add annotation
    DocSheet->>DocSheet: onAutoSave()
    alt DOCX
        DocSheet-->>DocSheet: preserve m_documentChanged
        User->>DocSheet: close viewer
        DocSheet-->>User: show save-confirmation dialog
        User->>DocSheet: Save
        DocSheet->>SaveAsPDF: save annotations as PDF
        SaveAsPDF-->>User: PDF with annotations
    else PDF/DJVU/XPS
        DocSheet->>TempPDF: save annotations
        DocSheet-->>DocSheet: clear m_documentChanged
    end
Loading

File-Level Changes

Change Details Files
Prevent DOCX annotation auto-save from clearing the modified state when annotations only exist in a temporary converted PDF.
  • Gate renderer annotation saving on the file type, excluding DOCX while retaining existing behavior for other formats.
  • Keep DOCX documents marked as changed so close-time confirmation can route Save through PDF export/save-as and preserve annotations.
reader/uiframe/DocSheet.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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 100 分,大于 70 分通过阈值,代码质量符合要求。本次修改针对 BUG-376501 修复了 DOCX 文件注释自动保存导致注释静默丢失的问题,修改精准、注释详尽、逻辑正确,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

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

建议: 语法正确,逻辑清晰。修改在 DocSheet::onAutoSave() 函数(reader/uiframe/DocSheet.cpp:2176)中增加 Dr::DOCX != fileType() 条件判断,C++ 语法正确,枚举比较使用 != 运算符合法。逻辑流程正确:跳过 DOCX 自动保存后 m_documentChanged 保持 true,fileChanged()(行618)返回 true,关闭时 CentralDocPage(行417)触发保存确认框,用户选择保存后走 saveAsCurrent() 另存为 PDF。该条件与 saveAsData()(行668)中已有的 Dr::DOCX != fileType() 模式一致,无边界条件问题。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

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

建议: 代码结构清晰,注释完整。新增5行注释详细说明了:1) DOCX 为转换打开格式,注释写入临时目录的 temp.pdf;2) 自动保存无法持久化的原因;3) 若照常保存清掉脏标志会导致关闭跳过确认框;4) 引用 BUG-376501;5) 设计意图为保持未保存状态由关闭确认框引导另存为 PDF。注释质量优秀,无代码重复,修改最小化(仅修改1个条件),符合现有代码风格。


3. 代码性能 ✅

评价: 优秀 ✅ 通过

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

建议: 性能良好,资源使用合理。新增条件 Dr::DOCX != fileType() 为 O(1) 枚举比较,开销可忽略。实际上对 DOCX 文件避免了不必要的文件 I/O 操作(m_renderer->save()),略有性能提升。无不必要的内存操作,无算法复杂度问题。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: 存在0个安全漏洞。本次修改仅影响 DOCX 文件的自动保存行为,不涉及用户输入处理、认证授权、敏感信息等安全相关逻辑。无命令注入、路径遍历、缓冲区溢出等风险。OCR 审查结果同样为0个问题。


💡 改进建议代码示例

// 当前修改已是最优实现,无需额外改进。
// onAutoSave() 中跳过 DOCX 自动保存的条件判断:
void DocSheet::onAutoSave()
{
    qCDebug(appLog) << "Auto-save triggered for:" << m_filePath;

    bool contentSaved = false;
    // DOCX 跳过自动保存,保持脏标志,由关闭确认框引导另存为 PDF
    if (m_documentChanged && Dr::DOCX != fileType()) {
        if (m_renderer && m_renderer->save()) {
            m_documentChanged = false;
            m_sidebar->changeResetModelData();
            contentSaved = true;
        }
    }
    // ...
}

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

@deepin-ci-robot

Copy link
Copy Markdown

[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.

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

@add-uos

add-uos commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit 9acd6e5 into linuxdeepin:master Sep 10, 2026
9 checks passed
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.

3 participants