Skip to content

Make each drag of a node one undo step - #573

Merged
paceholder merged 1 commit into
masterfrom
fix-drag-undo-steps
Dec 1, 2026
Merged

paceholder merged 1 commit into
masterfrom
fix-drag-undo-steps

Conversation

@paceholder

@paceholder paceholder commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation/refactoring

Description

MoveNodeCommand::mergeWith merged every move of the same nodes. Drag node A, release, drag A again: one undo reverted both drags. QUndoStack merges commands that follow each other and have the same id, and it does not know where a drag ends. This comes from the first undo implementation. The fix for #525 and #526 restored the flow of a drag through the model and the undo stack, and kept the merge.

MoveNodeCommand now has a move id. All commands that are created get the current id. A mouse press on a node or on a group calls MoveNodeCommand::beginMove(), which starts a new move. Commands merge only when the node set and the move id are the same. The mouse moves of one drag still merge into one step. A new press starts a new step. No id is stored in the graphics objects, and the scene is not changed.

Code that creates the command itself and never calls beginMove() merges as before, until the next press on a node or a group.

Testing

  • Qt version tested: 6 (offscreen). CI covers Qt5.
  • Existing tests still pass
  • Added tests for new functionality: two separate drags are two undo steps (fails without the fix), and one drag with ten mouse moves is one undo step.

Not tested: Qt5 locally, a group drag, a real mouse with fast moves.

Breaking changes?

Undo after two drags of the same node now reverts only the second drag. The API only gets a static function.

Related issue

Fixes #538.

QUndoStack merges commands with the same id and does not know where a drag ends, so two drags of the same nodes became one undo step. A press on a node or a group now starts a new move, and only the commands of one move merge.

Fixes #538
@paceholder
paceholder merged commit 66fc0e7 into master Dec 1, 2026
5 checks passed
@paceholder
paceholder deleted the fix-drag-undo-steps branch December 1, 2026 08:05
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.

Two separate node drags are one undo step

1 participant