Repository navigation
fix: correct column edit mode status after undo operation - #701
pppanghu77 wants to merge 1 commit into
Conversation
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideFixes 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 undosequenceDiagram
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
Flow diagram for undo and redo column status handlingflowchart 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())"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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
9351ed2 to
31e73bb
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整,存在轻微代码重复 ✅ 通过 潜在问题: 建议: ['提取公共逻辑为私有辅助函数,如 bool TextEdit::updateColumnEditStatusForCommand(const QUndoCommand *cmd), 两个公开函数分别传入 command(index()) 和 command(index()-1) 调用之。'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在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 代码审查工具自动生成 |
|
TAG Bot New tag: 6.6.9 |
Root Cause Analysis
In
undo_()(src/editor/dtextedit.cpp:3818),refreshUndoRedoColumnStatus()is called afterm_pUndoStack->undo(). Sinceundo()decrementsindex(),command(index())returns the just-undone (redo-pending) command rather than the current stack top. This causesm_bIsAltModto incorrectly remaintrueafter undoing the last column edit command, so subsequent keystrokes wrongly invokeinsertColumnEditTextEx()instead of normal insertion.Key evidence:
undo_()at line 3818 calls refresh after undo;refreshUndoRedoColumnStatus()at line 9165 usescommand(index()); Python simulation (before.log) confirmsm_bIsAltModstaystrueafter undo.Fix
Added a new private function
refreshUndoRedoColumnStatusAfterUndo()that checkscommand(index()-1)(the current applied stack top) instead ofcommand(index())(the just-undone redo-pending command). Called fromundo_()in place of the original function.redo_()path is unchanged and still uses the originalrefreshUndoRedoColumnStatus(). No signature changes to existing functions.Change Safety Assessment
Code Safety
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
根因分析
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()。不改变现有函数签名。改动安全评估
代码安全评估
业务影响范围
列编辑模式撤销/重做状态管理。用户在列编辑模式下输入后按 Ctrl+Z 撤销最后一个列编辑命令,应正确退出列编辑模式;中途撤销应保持列编辑模式。redo 路径不受影响。
验证建议
Summary by Sourcery
Bug Fixes: