Repository navigation
fix: sync column-edit selections on undo to restore highlight - #689
pppanghu77 wants to merge 1 commit into
Conversation
1. Root cause: DeleteTextUndoCommand::undo() and InsertTextUndoCommand::undo() column-edit branches restore text and cursors internally but only call setTextCursor(last cursor), without syncing m_ColumnEditSelections back to TextEdit::m_altModSelections or calling renderAllSelections() 2. Fix: add TextEdit::syncColumnEditSelections() that sets m_altModSelections and calls renderAllSelections(); call it via qobject_cast<TextEdit*> in both undo() column-edit branches 3. Impact: column-edit cut/insert undo now restores full multi-line selection highlight; non-column-edit paths unaffected; PMS 254289 (same pattern in InsertTextUndoCommand) fixed together Log: fix column-edit undo only showing selection on last line Influence: 1. Test column-edit multi-line select then cut then undo 2. Test column-edit multi-line insert then undo 3. Test normal (non-column) cut/insert undo for no regression 4. Test repeated undo/redo cycle in column-edit mode fix: 修复列编辑撤销后选中状态仅显示最后一行的问题 1. 根因:DeleteTextUndoCommand::undo() 和 InsertTextUndoCommand::undo() 列编辑分支恢复文本和光标后仅调用 setTextCursor(最后一个cursor), 未将 m_ColumnEditSelections 同步回 TextEdit::m_altModSelections, 也未调用 renderAllSelections() 2. 方案:新增 TextEdit::syncColumnEditSelections() 方法设置 m_altModSelections 并调用 renderAllSelections(),在两个 undo() 列编辑分支中通过 qobject_cast<TextEdit*> 安全调用 3. 影响:列编辑剪切/插入撤销后恢复完整多行选中高亮;非列编辑路径 不受影响;PMS 254289(InsertTextUndoCommand 同一缺陷)一并修复 Log: 修复列编辑撤销后选中状态仅显示最后一行的问题 Influence: 1. 测试列编辑多行选中后剪切再撤销 2. 测试列编辑多行插入后撤销 3. 测试普通模式剪切/插入撤销无回归 4. 测试列编辑模式下多次撤销/重做循环 PMS: BUG-241613
|
[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 guide (collapsed on small PRs)Reviewer's GuideFixes column-edit undo highlighting by synchronizing the restored selection list with TextEdit’s alternate selections and re-rendering all highlights, while preserving existing behavior for other editor types and normal editing. Sequence diagram for column-edit undo highlight restorationsequenceDiagram
participant Undo as UndoCommand
participant Edit as TextEdit
participant Render as SelectionRenderer
Undo->>Edit: setTextCursor(last selection cursor)
Undo->>Edit: syncColumnEditSelections(m_ColumnEditSelections)
Edit->>Edit: m_altModSelections = selections
Edit->>Render: renderAllSelections()
Render-->>Edit: restore highlights on all selected lines
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: ['无语法逻辑问题'] 2. 代码质量 ✅评价: 代码结构清晰,可读性好 ✅ 通过 潜在问题: 建议: ['可考虑在基类或公共工具类中提取一个辅助方法(如 syncColumnEditSelectionsIfTextEdit(QPlainTextEdit*, const QListQTextEdit::ExtraSelection&)),供两个 undo 命令复用,减少代码重复'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: ['无性能问题'] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: ['无安全问题'] 💡 改进建议代码示例// 可选的改进:提取公共辅助方法以减少重复
// 在公共工具类或基类中:
static void syncColumnEditSelectionsIfTextEdit(QPlainTextEdit *edit,
const QList<QTextEdit::ExtraSelection> &selections)
{
if (edit && !selections.isEmpty()) {
edit->setTextCursor(selections.last().cursor);
if (TextEdit *textEdit = qobject_cast<TextEdit*>(edit)) {
textEdit->syncColumnEditSelections(selections);
}
}
}
// 在 DeleteTextUndoCommand::undo() 和 InsertTextUndoCommand::undo() 中替换为:
// syncColumnEditSelectionsIfTextEdit(m_edit, m_ColumnEditSelections);
// syncColumnEditSelectionsIfTextEdit(m_pEdit, m_ColumnEditSelections);本报告由 AI 代码审查工具自动生成 |
Root Cause Analysis
DeleteTextUndoCommand::undo()andInsertTextUndoCommand::undo()column-edit branches restore text and internal cursor selections but only callsetTextCursor(last().cursor)— they never syncm_ColumnEditSelectionsback toTextEdit::m_altModSelectionsnor callrenderAllSelections(). SincerenderAllSelections()(dtextedit.cpp:2222) renders visual highlights fromm_altModSelections, and that list holds stale (post-cut) cursors after undo, the highlight only appears on the last line. Key evidence:deletetextundocommand.cpp:96sets only the last cursor;dtextedit.cpp:3047-3066(undo_()) does not updatem_altModSelections.Fix
Added
TextEdit::syncColumnEditSelections(const QList<QTextEdit::ExtraSelection> &)which setsm_altModSelectionsand callsrenderAllSelections(). BothDeleteTextUndoCommand::undo()andInsertTextUndoCommand::undo()column-edit branches now call it viaqobject_cast<TextEdit*>(m_edit)aftersetTextCursor. The cast ensures non-TextEditeditors are unaffected. PMS 254289 (same pattern inInsertTextUndoCommand) is fixed together.Change Safety Assessment
Code Safety
references = 0in change-safety analysis; no external callers of the modifiedundo()functions.qobject_castguards ensure non-TextEditeditors skip the new code path with no behavioral change.Business Impact Scope
qobject_castreturns null, original path executes).Verification Suggestion
根因分析
DeleteTextUndoCommand::undo()和InsertTextUndoCommand::undo()列编辑分支恢复文本和内部光标后仅调用setTextCursor(last().cursor),未将m_ColumnEditSelections同步回TextEdit::m_altModSelections,也未调用renderAllSelections()。由于renderAllSelections()(dtextedit.cpp:2222)依赖m_altModSelections渲染高亮,而该列表在剪切后持有陈旧光标,撤销后仅最后一行显示选中。关键证据:deletetextundocommand.cpp:96仅设最后一个光标;dtextedit.cpp:3047-3066(undo_())不更新m_altModSelections。修复方案
新增
TextEdit::syncColumnEditSelections(const QList<QTextEdit::ExtraSelection> &)方法,设置m_altModSelections并调用renderAllSelections()。DeleteTextUndoCommand::undo()和InsertTextUndoCommand::undo()列编辑分支在setTextCursor后通过qobject_cast<TextEdit*>(m_edit)安全调用该方法。非TextEdit类型编辑器不受影响。PMS 254289(InsertTextUndoCommand同一缺陷)一并修复。改动安全评估
代码安全评估
undo()函数;qobject_cast保护确保非TextEdit类型编辑器走原路径无行为变化。业务影响范围
qobject_cast返回 null,走原路径)。验证建议
Summary by Sourcery
Restore column-edit selection state and highlighting consistently after undo operations.
Bug Fixes:
Enhancements: