IDE-321 Feat: Finalize multi-step undo/redo system#5180
IDE-321 Feat: Finalize multi-step undo/redo system#5180harshsomankar123-tech wants to merge 28 commits into
Conversation
9a7eb0c to
bc828ac
Compare
There was a problem hiding this comment.
Pull request overview
Implements a project-scoped multi-step undo/redo mechanism by introducing a dedicated snapshot/history manager, wiring it into ScriptFragment/SpriteActivity, and updating UI/tests to reflect the new enabled/disabled behavior.
Changes:
- Added
ProjectUndoManagerto manage per-project snapshot stacks (undo/redo) and variable snapshots. - Updated
ScriptFragmentandSpriteActivityto drive undo/redo via the new manager and keep menu items visible but disabled when unavailable. - Added/updated unit + UI tests and ensured undo history is cleared on project delete/rename.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/fragment/ProjectUndoManager.java | New undo/redo snapshot manager with disk-backed snapshots, TTL cleanup, and clear helpers. |
| catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/fragment/ScriptFragment.java | Integrates multi-step undo/redo, adds async-guard, and refreshes UI after project reload. |
| catroid/src/main/java/org/catrobat/catroid/ui/SpriteActivity.java | Adds lazy ProjectUndoManager, introduces redo menu handling, and updates menu enable/visibility logic. |
| catroid/src/main/res/menu/menu_script_activity.xml | Adds redo action and defaults undo/redo to disabled + hidden until prepared. |
| catroid/src/main/java/org/catrobat/catroid/common/Constants.java | Adds UNDO_DIRECTORY_NAME constant for snapshot storage. |
| catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/fragment/ProjectListFragment.kt | Clears undo history when deleting/renaming projects from the list. |
| catroid/src/main/java/org/catrobat/catroid/ui/fragment/ProjectOptionsFragment.kt | Clears undo history on project rename/delete via project options. |
| catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/fragment/UndoTest.java | Updates existing undo assertions and adds multi-step + rapid-click coverage. |
| catroid/src/test/java/org/catrobat/catroid/ui/recyclerview/fragment/ProjectUndoManagerTest.java | Adds unit tests for stack limiting/history clearing (currently has issues). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
detekt found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
…ames and robust restoration.
211bbe7 to
fcd3cfa
Compare
There was a problem hiding this comment.
I've tested the latest apk and found the following issues:
- disabling bricks deletes the history: instead, enabling or disabling bricks should be handled as undoable/redoable actions.
- inserting new bricks is ignored for the history: instead, inserting bricks should be handled as undoable/redoable actions.
- copying bricks or blocks is ignored for the history: instead, copying bricks or blocks should be handled as undoable/redoable actions.
- moving bricks or blocks is ignored for the history: instead, moving bricks or blocks should be handled as undoable/redoable actions.
…comment operations
wslany
left a comment
There was a problem hiding this comment.
Thanks for the follow-up changes. I reviewed the latest push and it looks like the missing actions are now wired into the undo manager in ScriptFragment: insert, copy, move, and comment in/out now call copyProjectForUndoOption() before mutating the script.
I still see two issues that would be good to address before moving the ticket in PO review:
-
Starting a drag records an undo step even if the user cancels without changing anything
copyProjectForUndoOption()is called beforestartMoving(...)for move/copy flows. If the user starts moving a brick and then cancels/back-presses,SpriteActivity.onBackPressed()only callscancelMove(), but the snapshot remains on the undo stack. This creates a no-op history entry even though no project change was committed.Ideally, the undo snapshot should be created only when the move is actually committed, or canceled/removed when the drag is aborted.
-
The new actions are not yet protected by regression tests
The current script undo tests still mainly cover delete-based undo/redo. I couldn’t find meaningful tests for the newly supported actions:
- inserting a brick
- copying a brick
- copying a block/control structure
- moving a brick
- moving a block/control structure
- commenting/uncommenting bricks
- canceling a started move without creating a no-op undo entry
Since this undo/redo system will likely be extended later to project-level changes such as actors/objects, scenes, groups, looks, and sounds, it would be valuable to add explicit regression tests now for each newly supported script action. That would make the current behavior much safer to extend without accidentally breaking existing undo/redo coverage.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thanks for the follow-up changes. I reviewed the latest push, and the earlier drag-cancel bug looks fixed now: the undo snapshot for moves is deferred until the move is actually committed, so canceling a drag no longer leaves a no-op undo entry in history. I still see two remaining issues before I’d call this fully ready:
|
…dd UI integration tests
|
Thanks!!! One small, easy to fix remaining test gap: The new |
|



Jira Ticket: https://catrobat.atlassian.net/browse/IDE-321
Description
Implements a robust project-scoped multi-step undo/redo system. This PR focuses exclusively on the core reliability of the undo/redo chain, state persistence, and UI synchronization.
Key Fixes & Features:
code.xmlsnapshots by ensuring project saves before every undo/redo push.isUndoRedoInProgressguard to prevent overlapping async project loads during rapid clicking.findFragmentByTag→findFragmentById) so the script view correctly updates after every operation.sceneNameandspriteNameare correctly stored in all history entries.Screen Recording
Screen.Recording.2026-03-31.at.06.33.02.mov
Screen.Recording.2026-04-18.at.20.17.31.mov
Checklist for this pull request
Please review the contributing guidelines and wiki pages of this repository.