Repository navigation
fix: merge column-edit undo into single step - #706
Draft
pppanghu77 wants to merge 1 commit into
Draft
pppanghu77 wants to merge 1 commit into
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 GuideColumn-edit keystrokes now merge through QUndoCommand’s ID and mergeWith() mechanism, accumulating inserted text and the latest cursor positions so one undo reverses the full input. The undo path deletes the accumulated text length per cursor, while non-column/single-cursor commands remain non-mergeable. Sequence diagram for merged column-edit undo commandssequenceDiagram
actor User
participant Editor as DTextEdit
participant Stack as QUndoStack
participant Command as InsertTextUndoCommand
User->>Editor: insertColumnEditTextEx()
Editor->>Stack: push(InsertTextUndoCommand)
Stack->>Command: id()
Stack->>Command: mergeWith(other)
Command-->>Stack: append m_sInsertText and adopt latest cursor positions
User->>Stack: undo()
Stack->>Command: undo()
Command->>Command: delete accumulated m_sInsertText length per cursor
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
pppanghu77
marked this pull request as draft
October 29, 2026 20:53
1. Root cause: InsertTextUndoCommand did not implement mergeWith(), so QUndoStack::push() never merged consecutive column-edit keystrokes — each keypress created a separate undo entry 2. Fix: implement id() and mergeWith() to merge consecutive column-edit commands; fix undo() to delete m_sInsertText.length() chars per cursor; keep cmd1 original cursor positions in mergeWith() instead of replacing with cmd2's post-insert cursor; remove +1 offset in redo() so undo→redo→undo cycles do not drift; replace magic number 1001 with named constant 3. Impact: column-edit mode (ALT+mouse) now undoes multi-char input in one Ctrl+Z with correct deletion range; normal single-cursor mode unaffected Log: fix column-edit undo to merge consecutive keystrokes Influence: 1. Test column-edit mode multi-char input undo (e.g. type "//" then Ctrl+Z) 2. Test column-edit mode undo→redo→undo cycle for position drift 3. Test normal single-cursor mode undo (regression) fix: 列编辑模式下合并连续按键为单步撤销 1. 根因:InsertTextUndoCommand 未实现 mergeWith(),QUndoStack::push() 无法合并连续列编辑按键,每次按键产生独立撤销条目 2. 方案:实现 id() 和 mergeWith() 合并连续列编辑命令;修正 undo() 按 m_sInsertText.length() 逐光标删除对应字符数;mergeWith() 中保留 cmd1 原始光标位置,不替换为 cmd2 插入后光标;移除 redo() 中 +1 偏移 确保 undo→redo→undo 循环无位置漂移;用命名常量替换魔法数字 1001 3. 影响:列编辑模式(ALT+鼠标)多字符输入可一次 Ctrl+Z 撤销且删除位置 正确;普通单光标模式不受影响 Log: 修复列编辑模式下撤销输入不正确的问题 Influence: 1. 测试列编辑模式多字符输入撤销(如输入"//"后 Ctrl+Z) 2. 测试列编辑模式 undo→redo→undo 循环无位置漂移 3. 测试普通单光标模式撤销(回归) PMS: BUG-254289
pppanghu77
force-pushed
the
fix/pms-254289
branch
from
October 29, 2026 21:38
d23b362 to
687fd37
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root Cause Analysis
In column-edit mode (ALT+mouse, multi-cursor), each keystroke calls
insertColumnEditTextEx()which pushes a newInsertTextUndoCommandonto the customQUndoStack. However,InsertTextUndoCommanddid not implementmergeWith()orid(), soQUndoStack::push()never merged consecutive keystrokes — each keypress created a separate undo entry. Typing"//"required two Ctrl+Z presses to undo, instead of one.Key evidence:
inserttextundocommand.hhad nomergeWith()/id()declarations;dtextedit.cpp:267-279(insertColumnEditTextEx) pushes a new command per keystroke;QUndoCommand::mergeWith()base returnsfalseby default.Fix
Implemented
id()(returns constant 1001) andmergeWith()onInsertTextUndoCommand: consecutive column-edit commands are merged by concatenatingm_sInsertTextand adoptingother's cursor positions (which reflect the latest state afterother->redo()ran). Also fixedundo()column-edit branch to deletem_sInsertText.length()chars per cursor instead of a singledeleteChar()— necessary because after merging,m_sInsertTextis multi-char.Change Safety Assessment
Code Safety
mergeWith()returnsfalsewhenm_ColumnEditSelectionsis emptyBusiness Impact Scope
Column-edit mode (ALT+mouse multi-cursor) undo behavior is the only affected feature. Users typing multi-character text in column-edit mode will now undo the entire input with one Ctrl+Z. Normal editing mode is unaffected.
Verification Suggestion
Test column-edit mode with multi-char input (e.g. type
//orhello) then Ctrl+Z — should undo in one step. Also verify normal single-cursor mode undo works as before (regression check).根因分析
列编辑模式(ALT+鼠标多光标)下,每次按键调用
insertColumnEditTextEx()向自定义QUndoStack压入新的InsertTextUndoCommand。但该类未实现mergeWith()和id(),导致QUndoStack::push()无法合并连续按键——每次按键产生独立撤销条目。输入"//"需要按两次 Ctrl+Z 才能撤销,而非一次。关键证据:
inserttextundocommand.h无mergeWith()/id()声明;dtextedit.cpp:267-279(insertColumnEditTextEx)每次按键压入新命令;QUndoCommand::mergeWith()基类默认返回false。修复方案
为
InsertTextUndoCommand实现id()(返回常量 1001)和mergeWith():连续列编辑命令通过追加m_sInsertText并采用other的光标位置(other->redo()执行后的最新位置)进行合并。同时修正undo()列编辑分支,按m_sInsertText.length()逐光标删除对应字符数,而非单次deleteChar()——合并后m_sInsertText为多字符,必须按实际长度删除。改动安全评估
代码安全评估
mergeWith()在m_ColumnEditSelections为空时返回false业务影响范围
仅影响列编辑模式(ALT+鼠标多光标)的撤销行为。用户在列编辑模式下输入多字符文本后,一次 Ctrl+Z 即可撤销整段输入。普通编辑模式不受影响。
验证建议
测试列编辑模式多字符输入(如输入
//或hello)后 Ctrl+Z——应一步撤销。同时验证普通单光标模式撤销行为正常(回归检查)。Summary by Sourcery
Fix column-edit undo behavior so consecutive multi-cursor keystrokes are reverted together in one operation.
Bug Fixes:
Enhancements: