Repository navigation
fix: merge column-edit undo commands for single-step undo - #688
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 GuideUpdates InsertTextUndoCommand to merge consecutive column-edit character insertions and removes the combined text in a single undo operation, while leaving normal text insertion commands unmerged. Sequence diagram for merged column-edit undosequenceDiagram
actor User
participant Edit as QPlainTextEdit
participant Stack as QUndoStack
participant Cmd as InsertTextUndoCommand
User->>Edit: Type character
Edit->>Cmd: InsertTextUndoCommand
Edit->>Stack: push(Cmd)
User->>Edit: Type next character
Edit->>Cmd: InsertTextUndoCommand
Edit->>Stack: push(Cmd)
Stack->>Cmd: id()
Stack->>Cmd: mergeWith(other)
Cmd-->>Stack: true, append m_sInsertText
User->>Stack: undo()
Stack->>Cmd: undo()
Cmd->>Cmd: delete combined m_sInsertText
Flow diagram for column-edit command mergingflowchart TD
A[InsertTextUndoCommand pushed] --> B{"id() matches 1001?"}
B -- No --> C[Keep separate undo command]
B -- Yes --> D{Both m_ColumnEditSelections non-empty?}
D -- No --> C
D -- Yes --> E[mergeWith appends m_sInsertText]
E --> F[One undo removes merged text]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
1. Root cause: InsertTextUndoCommand lacked id()/mergeWith() overrides, so QUndoStack never merged consecutive single-char column-edit insert commands; each keypress produced a separate undo step 2. Fix: add id() returning kColumnEditInsertCommandId and mergeWith() that appends text when both commands have non-empty m_ColumnEditSelections; fix undo() to delete m_sInsertText.length() chars; fix redo() selection to use m_sInsertText.length() without +1 so merged multi-char text is correctly selected on redo path 3. Impact: column-edit undo now removes entire typed text in one step; redo path also correct after merge; normal text insert unaffected (m_ColumnEditSelections is empty, so mergeWith returns false) Log: fix column-edit undo to remove all typed text in a single undo step Influence: 1. Test column-edit mode: type multiple chars then Ctrl+Z, verify single-step undo 2. Test column-edit redo after undo: Ctrl+Shift+Z then Ctrl+Z again, verify no data corruption 3. Test normal text editing undo/redo remains unchanged 4. Test column-edit with mixed operations (insert, delete, undo, redo) fix: 修复列编辑模式撤销需逐字符撤销的问题 1. 根因:InsertTextUndoCommand 未重写 id()/mergeWith(),QUndoStack 无法合并列编辑模式下连续按键产生的单字符插入命令,每次按键产生 独立的撤销步骤 2. 方案:添加 id() 返回 kColumnEditInsertCommandId 和 mergeWith(), 当双方 m_ColumnEditSelections 均非空时合并文本;修复 undo() 列编辑 分支按 m_sInsertText.length() 删除;修复 redo() 选区计算移除 +1, 确保合并后多字符文本在 redo 路径正确选中 3. 影响:列编辑撤销现在可一步撤销全部输入;redo 路径在合并后同样 正确;普通文本编辑不受影响(m_ColumnEditSelections 为空, mergeWith 返回 false) Log: 修复列编辑模式撤销需逐字符撤销的问题 Influence: 1. 测试列编辑模式:输入多个字符后 Ctrl+Z,验证一步撤销 2. 测试列编辑撤销后重做再撤销:Ctrl+Shift+Z 后 Ctrl+Z,验证无数据损坏 3. 测试普通文本编辑的撤销/重做行为保持不变 4. 测试列编辑混合操作(插入、删除、撤销、重做) PMS: BUG-254289
6ef56d9 to
c5945a1
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: ['mergeWith() 仅合并 m_sInsertText 而未合并 m_ColumnEditSelections, 当前在列编辑连续输入场景下逻辑正确(所有 cursor 同步前进), 建议在注释中说明此合并策略的前提条件,便于后续维护者理解。'] 2. 代码质量 ✅评价: 代码结构清晰,注释完整性略有不足 ✅ 通过 潜在问题: 建议: ['建议为 mergeWith() 添加注释,说明合并策略:仅合并 m_sInsertText, 依赖列编辑模式下所有 cursor 同步前进的特性,无需合并 selections。'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例// 建议为 mergeWith() 添加注释说明合并策略 bool InsertTextUndoCommand::mergeWith(const QUndoCommand *other) {
if (other->id() != id())
return false;
const auto *cmd = static_cast<const InsertTextUndoCommand *>(other);
if (m_ColumnEditSelections.isEmpty() || cmd->m_ColumnEditSelections.isEmpty())
return false;
// 列编辑模式下连续输入时,所有 cursor 同步前进,
// 仅需合并插入文本即可正确执行 undo/redo,无需合并 selections。
m_sInsertText += cmd->m_sInsertText;
return true;
}本报告由 AI 代码审查工具自动生成 |
Fix: Column-edit undo merges consecutive insert commands (PMS BUG-254289)
Problem
In column-edit mode (ALT+mouse), typing multiple characters then pressing Ctrl+Z undoes one character at a time instead of the entire input. This is because InsertTextUndoCommand does not override id()/mergeWith(), so QUndoStack never merges consecutive single-char insert commands.
Root Cause
InsertTextUndoCommand lacks id() and mergeWith() overrides. Each keypress in column-edit mode creates a separate InsertTextUndoCommand pushed to the undo stack. Without id()/mergeWith(), QUndoStack treats each as independent, requiring one undo per character.
Fix
Verification
Minimal Qt6 demo validated: without mergeWith(), typing "//" requires 2 undo steps; with mergeWith(), 1 undo step removes both characters.
Impact
PMS: BUG-254289
Summary by Sourcery
Bug Fixes: