Skip to content

fix: render all selections after undo/redo in column edit - #705

Draft
pppanghu77 wants to merge 1 commit into
linuxdeepin:masterfrom
pppanghu77:agent/agent/3f28a708a413
Draft

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

Conversation

@pppanghu77

@pppanghu77 pppanghu77 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

In deepin-editor's column-edit mode (Alt+drag), after cutting or deleting multi-line text and then undoing, only the last line's selection highlight is restored while other lines lose their highlight. The root cause is that DeleteBackAltCommand::undo() and redo() (src/editor/deletebackcommond.cpp) call restoreColumnEditSelection() which only updates the member variable m_altModSelections without calling renderAllSelections() to push selections to QPlainTextEdit::setExtraSelections(). The subsequent setTextCursor(last().cursor) only renders the last line's cursor selection. The normal Alt+drag path (dtextedit.cpp mouseMoveEvent) correctly calls renderAllSelections() after building the selection list.

Fix Approach

Add m_edit->renderAllSelections() after restoreColumnEditSelection() in both DeleteBackAltCommand::undo() and redo(), so that m_altModSelections is pushed to Qt's rendering layer via setExtraSelections(). This aligns the undo/redo path with the normal selection path.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Target lines were introduced by commit 889fa1969 (PMS 273663) which added restoreColumnEditSelection() but omitted the render call — this fix supplements that omission without reverting the historical fix
  • renderAllSelections() is an existing public method already called by the normal Alt+drag path; no signature changes, no public member changes, 0 external references affected

Business Impact Scope

  • Column-edit mode — Alt+drag multi-line selection followed by cut/delete, then undo/redo
  • Users selecting multiple lines via column edit, cutting or deleting, then undoing will now see all lines' highlight correctly restored instead of only the last line

Verification Suggestion

Test column-edit multi-line selection → cut/delete → undo → verify all lines highlighted; then redo → verify all lines highlighted. Also verify normal column-edit selection highlight has no regression.


根因分析

在 deepin-editor 列编辑模式(Alt+拖拽)下,剪切或删除多行文本后撤销,仅最后一行的选中高亮恢复,其余行高亮消失。根因是 DeleteBackAltCommand::undo() 和 redo()(src/editor/deletebackcommond.cpp)调用 restoreColumnEditSelection() 仅更新成员变量 m_altModSelections,未调用 renderAllSelections() 将选中列表推送到 QPlainTextEdit::setExtraSelections() 渲染层。随后的 setTextCursor(last().cursor) 仅渲染最后一行光标的选中区域。正常 Alt+拖拽路径(dtextedit.cpp mouseMoveEvent)会正确调用 renderAllSelections()。

修复方案

在 DeleteBackAltCommand::undo() 和 redo() 的 restoreColumnEditSelection() 调用之后增加 m_edit->renderAllSelections() 调用,使 m_altModSelections 通过 setExtraSelections() 推送到 Qt 渲染层,与正常选中路径保持一致。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 目标行由 commit 889fa1969(PMS 273663)引入,该提交添加了 restoreColumnEditSelection() 但遗漏了渲染调用——本次修复补充该遗漏,不撤销历史修复
  • renderAllSelections() 是已有公共方法,正常 Alt+拖拽路径已调用;无签名变更、无公开成员变更、0 条外部引用受影响

业务影响范围

  • 列编辑模式 — Alt+拖拽多行选中后剪切/删除,再撤销/重做
  • 用户在列编辑模式选中多行剪切或删除后撤销,将看到所有行高亮正确恢复,而非仅最后一行

验证建议

测试列编辑多行选中 → 剪切/删除 → 撤销 → 验证所有行高亮恢复;再重做 → 验证所有行高亮恢复。同时验证正常列编辑选中高亮无回归。

Summary by Sourcery

Bug Fixes:

  • Restore all column-edit selection highlights after undoing or redoing delete and insert operations.

@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

@pppanghu77
pppanghu77 marked this pull request as draft October 29, 2026 19:39
@sourcery-ai

sourcery-ai Bot commented Oct 29, 2026

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

Reviewer's Guide

Fixes column-edit undo/redo rendering by explicitly pushing the restored multi-line selection list to the editor after selection state restoration, preventing only the last line from appearing highlighted.

Sequence diagram for column-edit undo/redo selection rendering

sequenceDiagram
    participant Command as DeleteBackAltCommand
    participant Editor as DTextEdit
    participant Qt as QPlainTextEdit

    Command->>Editor: restoreColumnEditSelection(m_columnEditSelections)
    Command->>Editor: setTextCursor(m_columnEditSelections.last().cursor)
    Command->>Editor: renderAllSelections()
    Editor->>Qt: setExtraSelections(m_altModSelections)
    Qt-->>Editor: Render all restored line highlights
Loading

File-Level Changes

Change Details Files
Restore rendering of all column-edit selections after undo and redo.
  • Call renderAllSelections() after restoring the saved column selections in undo().
  • Call renderAllSelections() after restoring the saved column selections in redo().
  • Keep the existing final cursor restoration while synchronizing the full selection list with Qt’s extra-selection layer.
src/editor/deletebackcommond.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

@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()/redo() in DeleteBackAltCommand,
   DeleteTextUndoCommand and InsertTextUndoCommand call
   restoreColumnEditSelection() which only updates the member variable
   m_altModSelections but never pushes it to QPlainTextEdit::setExtraSelections()
2. Fix: add m_edit->renderAllSelections() after restoreColumnEditSelection()
   in all affected undo()/redo() methods so all column-edit highlight
   lines are rendered
3. Impact: only affects column-edit undo/redo highlight rendering, normal
   Alt-drag selection path already calls renderAllSelections() unchanged

Log: fix incomplete column edit selection highlight after undo/redo

Influence:
1. Test column-edit multi-line cut then undo, verify all lines highlighted
2. Test column-edit multi-line delete then undo, verify all lines highlighted
3. Test undo then redo in column edit, verify all lines highlighted
4. Verify normal column-edit selection highlight has no regression

fix: 修复列编辑撤销/重做后选中高亮不完全

1. 根因:DeleteBackAltCommand、DeleteTextUndoCommand 和
   InsertTextUndoCommand 的 undo()/redo() 调用
   restoreColumnEditSelection() 仅更新成员变量 m_altModSelections,
   未调用 renderAllSelections() 推送到 QPlainTextEdit 渲染层
2. 方案:在所有受影响的 undo()/redo() 的 restoreColumnEditSelection()
   后增加 m_edit->renderAllSelections() 调用,使全部列编辑选中行正确渲染
3. 影响:仅影响列编辑撤销/重做的高亮渲染,正常 Alt+拖拽选中路径
   已调用 renderAllSelections(),行为不变

Log: 修复列编辑撤销重做后选中高亮不完全的问题

Influence:
1. 测试列编辑多行剪切后撤销,验证所有行高亮恢复
2. 测试列编辑多行删除后撤销,验证所有行高亮恢复
3. 测试撤销后重做,验证所有行高亮恢复
4. 验证正常列编辑选中高亮无回归

PMS: BUG-241613
@pppanghu77
pppanghu77 force-pushed the agent/agent/3f28a708a413 branch from 08cd146 to b795235 Compare October 29, 2026 20:55
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