Skip to content

fix: correct column edit mode status after undo operation - #701

Open
pppanghu77 wants to merge 1 commit into
linuxdeepin:masterfrom
pppanghu77:agent/agent/a90e1e7eea4a
Open

pppanghu77 wants to merge 1 commit into
linuxdeepin:masterfrom
pppanghu77:agent/agent/a90e1e7eea4a

Conversation

@pppanghu77

@pppanghu77 pppanghu77 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

In undo_() (src/editor/dtextedit.cpp:3818), refreshUndoRedoColumnStatus() is called after m_pUndoStack->undo(). Since undo() decrements index(), command(index()) returns the just-undone (redo-pending) command rather than the current stack top. This causes m_bIsAltMod to incorrectly remain true after undoing the last column edit command, so subsequent keystrokes wrongly invoke insertColumnEditTextEx() instead of normal insertion.

Key evidence: undo_() at line 3818 calls refresh after undo; refreshUndoRedoColumnStatus() at line 9165 uses command(index()); Python simulation (before.log) confirms m_bIsAltMod stays true after undo.

Fix

Added a new private function refreshUndoRedoColumnStatusAfterUndo() that checks command(index()-1) (the current applied stack top) instead of command(index()) (the just-undone redo-pending command). Called from undo_() in place of the original function. redo_() path is unchanged and still uses the original refreshUndoRedoColumnStatus(). No signature changes to existing functions.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • New private function, no signature changes, redo path unaffected
  • Historical insight: target function introduced by commit 889fa19 (PMS 273663, "restore column selection after undo"). This fix corrects the index error in the undo path without reverting the historical fix; redo path still uses original function.

Business Impact Scope

Column edit mode undo/redo state management. Users editing in column mode and pressing Ctrl+Z to undo the last column edit should correctly exit column mode; intermediate undo should keep column mode. Redo path is unaffected.

Verification Suggestion

  • Test column edit mode input then undo — verify mode exits correctly after final undo
  • Test multiple column edits then sequential undo — verify intermediate undo keeps column mode
  • Test redo after undo in column edit mode — verify no regression
  • Test normal edit mode undo/redo — verify no regression

根因分析

undo_()(src/editor/dtextedit.cpp:3818)在调用 m_pUndoStack->undo() 后调用 refreshUndoRedoColumnStatus()。由于 undo() 会递减 index(),command(index()) 返回的是刚被撤销的待重做命令而非当前栈顶已应用命令。这导致撤销最后一个列编辑命令后 m_bIsAltMod 错误保持为 true,后续输入错误走 insertColumnEditTextEx() 列编辑插入。

修复方案

新增私有函数 refreshUndoRedoColumnStatusAfterUndo(),检查 command(index()-1)(当前已应用栈顶)而非 command(index()),在 undo_() 中替代原函数调用。redo_() 路径保持不变,仍使用原 refreshUndoRedoColumnStatus()。不改变现有函数签名。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 新增独立私有函数,不改签名,redo 路径不受影响
  • 历史洞察:目标函数由 commit 889fa19(PMS 273663)引入,本次修复修正 undo 路径索引错误,不撤销历史修复意图,redo 路径仍使用原函数

业务影响范围

列编辑模式撤销/重做状态管理。用户在列编辑模式下输入后按 Ctrl+Z 撤销最后一个列编辑命令,应正确退出列编辑模式;中途撤销应保持列编辑模式。redo 路径不受影响。

验证建议

  • 测试列编辑模式输入后撤销,验证撤销后正确退出列编辑模式
  • 测试列编辑模式多次输入后逐次撤销,验证中途撤销保持列编辑模式
  • 测试列编辑模式撤销后重做,验证无回归
  • 测试普通编辑模式撤销/重做,验证无回归

Summary by Sourcery

Bug Fixes:

  • Correct column edit mode state after undo so undoing the final column edit exits column mode and subsequent input uses normal insertion.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pppanghu77

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

@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Reviewer's Guide

Fixes stale column edit mode after undo by using a dedicated post-undo refresh path that accounts for the undo stack index decrement, while leaving redo and normal status handling unchanged.

Sequence diagram for correcting column mode after undo

sequenceDiagram
    participant TextEdit
    participant UndoStack
    participant Status

    TextEdit->>UndoStack: undo()
    UndoStack-->>TextEdit: index() decremented
    TextEdit->>Status: refreshUndoRedoColumnStatusAfterUndo()
    Status->>UndoStack: command(index() - 1)
    UndoStack-->>Status: current applied command
    alt column edit state changed
        Status->>TextEdit: update m_bIsAltMod and selections
        TextEdit->>TextEdit: renderAllSelections()
        TextEdit->>TextEdit: update()
    else no applied command
        Status->>TextEdit: clear column mode and selections
    end
Loading

Flow diagram for undo and redo column status handling

flowchart TD
    A[Undo or redo requested] --> B{Operation}
    B -->|undo_| C["m_pUndoStack->undo()"]
    C --> D["refreshUndoRedoColumnStatusAfterUndo()"]
    D --> E["command(index() - 1)"]
    B -->|redo_| F["m_pUndoStack->redo()"]
    F --> G["refreshUndoRedoColumnStatus()"]
    G --> H["command(index())"]
Loading

File-Level Changes

Change Details Files
Correct column edit mode state restoration after undo by inspecting the currently applied undo-stack command.
  • Route undo handling through a new post-undo status refresh helper.
  • Use index()-1 to identify the applied stack top after undo.
  • Reset column mode and selections when no applied command remains, while preserving updates for active column edits.
  • Keep the existing refresh logic and behavior for redo unchanged.
src/editor/dtextedit.cpp
src/editor/dtextedit.h

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

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

1. Root cause: undo_() called refreshUndoRedoColumnStatus() after
   m_pUndoStack->undo() which decrements index(), so command(index())
   returned the just-undone (redo-pending) command instead of the
   current stack top, keeping m_bIsAltMod=true after undoing the last
   column edit command
2. Fix: add refreshUndoRedoColumnStatusAfterUndo() that checks
   command(index()-1) (current applied stack top) instead of
   command(index()) to correctly determine edit mode after undo
3. Impact: only undo_() path is affected; redo_() still uses original
   refreshUndoRedoColumnStatus(), no signature changes

Log: fix column edit mode status not updating correctly after undo

Influence:
1. Test column edit mode input then undo, verify mode exits correctly
2. Test multiple column edits then sequential undo, verify intermediate
   undo keeps column mode while final undo exits
3. Test redo after undo in column edit mode, verify no regression
4. Test normal edit mode undo/redo, verify no regression

fix: 修复列编辑模式下撤销输入不正确的问题

1. 根因:undo_() 在 m_pUndoStack->undo() 之后调用
   refreshUndoRedoColumnStatus(),undo() 会递减 index(),导致
   command(index()) 返回的是刚被撤销的待重做命令而非当前栈顶,
   撤销最后一个列编辑命令后 m_bIsAltMod 错误保持为 true
2. 方案:新增 refreshUndoRedoColumnStatusAfterUndo() 检查
   command(index()-1)(当前已应用栈顶)而非 command(index())
   来正确判断撤销后的编辑模式
3. 影响:仅影响 undo_() 路径,redo_() 仍使用原
   refreshUndoRedoColumnStatus(),不改变函数签名

Log: 修复列编辑模式下撤销后编辑模式状态不正确的问题

Influence:
1. 测试列编辑模式输入后撤销,验证撤销后正确退出列编辑模式
2. 测试列编辑模式多次输入后逐次撤销,验证中途撤销保持列编辑模式
3. 测试列编辑模式撤销后重做,验证无回归
4. 测试普通编辑模式撤销/重做,验证无回归

Bug: #254289
@pppanghu77
pppanghu77 force-pushed the agent/agent/a90e1e7eea4a branch from 9351ed2 to 31e73bb Compare October 28, 2026 19:34
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复了撤销操作后列编辑模式状态不正确的问题,新增 refreshUndoRedoColumnStatusAfterUndo() 函数正确处理 undo 后 index() 递减的语义差异。 语法逻辑正确,边界处理完善,性能无瓶颈,无安全漏洞。OCR 指出两个函数存在代码重复, 建议提取公共逻辑为辅助函数,属轻微可维护性改进建议,不影响功能正确性。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

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

建议: []


2. 代码质量 ✅

评价: 代码结构清晰,注释完整,存在轻微代码重复 ✅ 通过

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

建议: ['提取公共逻辑为私有辅助函数,如 bool TextEdit::updateColumnEditStatusForCommand(const QUndoCommand *cmd), 两个公开函数分别传入 command(index()) 和 command(index()-1) 调用之。']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

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

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例

// 建议提取公共逻辑,消除代码重复
bool TextEdit::updateColumnEditStatusForCommand(const QUndoCommand *cmd)
{
    if (!cmd)
        return false;

    const int id = cmd->id();
    const bool columnEdit = (id != Utils::IdDefault) && (Utils::IdColumnEdit & id);
    if (columnEdit != m_bIsAltMod) {
        m_bIsAltMod = columnEdit;
        if (!m_bIsAltMod) {
            m_altModSelections.clear();
        }
        return true;
    }

    // in column editing, update every time.
    if (columnEdit) {
        return true;
    }

    return false;
}

bool TextEdit::refreshUndoRedoColumnStatus()
{
    return updateColumnEditStatusForCommand(m_pUndoStack->command(m_pUndoStack->index()));
}

bool TextEdit::refreshUndoRedoColumnStatusAfterUndo()
{
    return updateColumnEditStatusForCommand(m_pUndoStack->command(m_pUndoStack->index() - 1));
}

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

@deepin-bot

deepin-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.6.9
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #698

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.

2 participants