Skip to content

Revert "fix(editor): persist file encoding across sessions" (bug-fix-365847) - #492

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
GongHeng2017:agent/bugfix/fba808e4
Jul 29, 2026
Merged

Revert "fix(editor): persist file encoding across sessions" (bug-fix-365847)#492
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
GongHeng2017:agent/bugfix/fba808e4

Conversation

@GongHeng2017

@GongHeng2017 GongHeng2017 commented Jul 29, 2026

Copy link
Copy Markdown

回退 PR #491(bug-fix-365847)

背景

PR #491(commit 1d549851,"fix(editor): persist file encoding across sessions")已合并入 release/eagle,用于修复 BUG-365847(切换编码保存后重新打开编码丢失)。

由于当前需求调整,需要回退该提交。

回退内容

使用 git revert 1d549851 精确反向应用 PR #491 的全部变更,将代码恢复到该 PR 合并前(9735678e)的状态:

文件 回退内容
src/common/fileloadthread.h 移除 setPreferredEncode() 方法和 m_preferredEncode 成员变量
src/common/fileloadthread.cpp 移除 setPreferredEncode() 实现;run() 恢复为完全依赖自动探测
src/editor/dtextedit.h 移除 setTextEncode() setter 和 readEncodeHistoryRecord(filepath) 重载声明
src/editor/dtextedit.cpp 移除 readEncodeHistoryRecord(filepath) 重载实现
src/editor/editwrapper.cpp 移除 openFile/saveFile/forceSaveInvalidCharFile/saveDraftFile 中编码历史相关调用
src/widgets/window.cpp 移除 saveAsFileToDisk 中编码历史记录调用

变更规模:6 个文件,+1 行 / -79 行(与 PR #491 的 +79/-1 互为逆操作)。已逐文件校验,回退后内容与合并前提交 9735678e 完全一致。

验证

关联

Log: 回退编码历史持久化机制改动
Bug: https://pms.uniontech.com/bug-view-365847.html

Summary by Sourcery

Revert the previously introduced file encoding persistence behavior and restore the editor’s prior encoding handling.

Enhancements:

  • Remove use of saved encoding history when opening and saving files so file loading reverts to automatic encoding detection behavior.

Chores:

  • Delete APIs and data members related to preferred file encoding and per-file encoding history that were added for BUG-365847.

This reverts commit 1d54985.

需求调整,回退 PR linuxdeepin#491(bug-fix-365847)的编码历史持久化改动,
代码恢复到该 PR 合并前的状态。

Log: 回退编码历史持久化机制改动
Bug: https://pms.uniontech.com/bug-view-365847.html

@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 @GongHeng2017, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@sourcery-ai

sourcery-ai Bot commented Jul 29, 2026

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

Reviewer's Guide

This PR cleanly reverts a previous change that persisted file encoding history and preferred encodings across sessions, restoring the editor’s behavior to rely solely on automatic detection and removing all call sites and data members related to the reverted feature.

Sequence diagram for file open without encoding history persistence

sequenceDiagram
    actor User
    participant Window
    participant EditWrapper
    participant TextEdit
    participant FileLoadThread
    participant DetectCode

    User->>Window: saveAsFileToDisk
    Window->>EditWrapper: openFile(filepath, qstrTruePath, bKeep)
    EditWrapper->>TextEdit: setFilePath(filepath)
    EditWrapper->>FileLoadThread: FileLoadThread(filepath)
    EditWrapper->>FileLoadThread: run
    FileLoadThread->>FileLoadThread: QFile.open
    FileLoadThread->>FileLoadThread: read(indata)
    FileLoadThread->>DetectCode: GetFileEncodingFormat(m_strFilePath, indata)
    DetectCode-->>FileLoadThread: encode
    FileLoadThread-->>EditWrapper: sigPreProcess(encode, content)
Loading

File-Level Changes

Change Details Files
Remove preferred-encoding support from file loading and revert to pure auto-detection.
  • Delete FileLoadThread::setPreferredEncode and its m_preferredEncode member.
  • Simplify FileLoadThread::run() to always call DetectCode::GetFileEncodingFormat for large files instead of honoring a preferred encoding.
  • Ensure no callers attempt to set a preferred encoding before starting the load thread.
src/common/fileloadthread.h
src/common/fileloadthread.cpp
src/editor/editwrapper.cpp
Remove per-file encoding history lookup and write-back from the text editor and window logic.
  • Remove TextEdit::setTextEncode inline setter and the overload TextEdit::readEncodeHistoryRecord(const QString &filepath).
  • Delete implementation of the filepath-based readEncodeHistoryRecord overload in dtextedit.cpp.
  • Strip calls that read/write encoding history during open/save/save-as/draft save flows in EditWrapper and Window.
  • Restore the previous behavior where encode history helpers remain present but unused ("dead code").
src/editor/dtextedit.h
src/editor/dtextedit.cpp
src/editor/editwrapper.cpp
src/widgets/window.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

★ 总体评分:100分

■ 【总体评价】

代码实现了移除文件编码历史记录功能并恢复自动编码探测,整体逻辑清晰且无安全风险
逻辑正确且代码结构得到精简,未引入任何安全漏洞,故给予满分

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

移除了FileLoadThread::setPreferredEncodeTextEdit::readEncodeHistoryRecord(filepath)及相关调用,代码逻辑连贯,未发现空指针或悬垂引用。在fileloadthread.cpprun函数中,移除条件判断后直接调用DetectCode::GetFileEncodingFormat,符合预期流程。
潜在问题:无
建议:无需修改

  • 2.代码质量(良好)✓

移除了不再需要的成员变量m_preferredEncodem_textEncode的设置,以及相关的配置读写逻辑,降低了代码复杂度,使得打开文件的流程更加直接和易于维护。
潜在问题:无
建议:无需修改

  • 3.代码性能(无性能问题)✓

移除历史记录后,每次打开文件均需进行编码自动探测。对于大文件(超过40MB),代码依然采用读取1MB头部数据进行探测的策略,避免了全文件扫描,性能影响可忽略不计。
潜在问题:无
建议:无需修改

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次变更仅为代码删除和逻辑回滚,未引入新的外部输入处理或危险函数调用,且移除了原先复杂的字符串解析逻辑readEncodeHistoryRecord,反而降低了潜在的安全风险。

  • 建议:无需修改

■ 【改进建议代码示例】

// 本次变更无需修复,代码已处于良好状态。

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: GongHeng2017, max-lvs

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

@GongHeng2017

Copy link
Copy Markdown
Author

/merge

@deepin-bot
deepin-bot Bot merged commit 4171b46 into linuxdeepin:release/eagle Jul 29, 2026
20 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